Skip to content
Advertisement

Does join speed depend on total amount of records in the table?

If i have a table that looks like this (composite PK user_id + asset_type):

|user_id|asset_type|amount|

One user have at most 10 records in this table. Imagine if there 200 millions records and i want to join this table on user_id. Does speed of join going to depend on total amount of records in the table?

Advertisement

Answer

That depends.

If PostgreSQL decides to use a nested loop join and your table is the inner table, then the join can use the primary key index, and the speed of the join will by practically independent of the size of your table.

With any other join strategy, the execution time of the join will depend on the table size.

Which join strategy PostgreSQL chooses will mostly depend on how many user_ids you join the table with. The fewer, the more likely you will get a nested loop join.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement