Untitled

mail@pastecode.io avatar
unknown
pgsql
a year ago
1.3 kB
4
Indexable
Never
#1
SELECT s.data, j.data FROM scan_table s JOIN join_table j ON s.id = j.num WHERE s.id = 8000;

# Query Plan:
# Nested Loop (cost=0.29..8401.32 rows=1 width=1034) (actual time=2.015..25.392 rows=1 loops=1)
# -> Index Scan using scan_table_pkey on scan_table s (cost=0.29..8.31 rows=1 width=521) (actual time=0.016..0.017 rows=1 loops=1)
# Index Cond: (id = 8000)
# -> Seq Scan on join_table j (cost=0.00..8393.00 rows=1 width=521) (actual time=1.997..25.373 rows=1 loops=1)
# Filter: (num = 8000)
# Rows Removed by Filter: 99999
# Planning time: 0.126 ms
# Execution time: 25.425 ms
# (8 rows)

# =============================================================================

#2
SELECT s.data, j.data FROM scan_table s JOIN join_table j ON s.id > j.id WHERE s.id = 8000; 

# Query Plan:
# Nested Loop (cost=0.58..3677.26 rows=33333 width=1034) (actual time=0.169..10.954 rows=7999 loops=1)
# -> Index Scan using scan_table_pkey on scan_table s (cost=0.29..8.31 rows=1 width=521) (actual time=0.087..0.089 rows=1 loops=1)
# Index Cond: (id = 8000)
# -> Index Scan using join_table_pkey on join_table j (cost=0.29..3335.62 rows=33333 width=521) (actual time=0.068..8.094 rows=7999 loops=1) Index Cond: (s.id > id)
# Planning time: 0.250 ms
# Execution time: 11.896
# ms (7 rows)