You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I could not get some hint to work a bigger query and narrowed the issue to this pattern:
CREATETABLEt1 (id intPRIMARY KEY, val int);
CREATETABLEt2 (id intPRIMARY KEY, val int);
EXPLAIN
/*+ MergeJoin(t1 t2) Rows(t1 t2 #1234)*/SELECT*FROM (SELECT DISTINCTON (id) *FROM t1) S
INNER JOIN t2 ONS.id=t2.id;
QUERY PLAN
Hash Join (cost=61.01..150.50 rows=2260 width=16)
Hash Cond: (t1.id=t2.id)
-> Unique (cost=0.15..83.71 rows=2260 width=8)
-> Index Scan using t1_pkey on t1 (cost=0.15..78.06 rows=2260 width=8)
-> Hash (cost=32.60..32.60 rows=2260 width=8)
-> Seq Scan on t2 (cost=0.00..32.60 rows=2260 width=8)
Without the DISTINCT ON, the hints work fine:
EXPLAIN
/*+ MergeJoin(t1 t2) Rows(t1 t2 #1234)*/SELECT*FROM (SELECT*FROM t1) S
INNER JOIN t2 ONS.id=t2.id;
QUERY PLAN
Merge Join (cost=0.31..190.01 rows=1234 width=16)
Merge Cond: (t1.id=t2.id)
-> Index Scan using t1_pkey on t1 (cost=0.15..78.06 rows=2260 width=8)
-> Index Scan using t2_pkey on t2 (cost=0.15..78.06 rows=2260 width=8)
Using ANY_subquery does not work
EXPLAIN
/*+ MergeJoin(ANY_subquery t2) Rows(ANY_subquery t2 #1234)*/SELECT*FROM (SELECT DISTINCTON (id) *FROM t1) S
INNER JOIN t2 ONS.id=t2.id;
QUERY PLAN
Hash Join (cost=61.01..150.50 rows=2260 width=16)
Hash Cond: (t1.id=t2.id)
-> Unique (cost=0.15..83.71 rows=2260 width=8)
-> Index Scan using t1_pkey on t1 (cost=0.15..78.06 rows=2260 width=8)
-> Hash (cost=32.60..32.60 rows=2260 width=8)
-> Seq Scan on t2 (cost=0.00..32.60 rows=2260 width=8)
Merge joins are possible, if I set ENABLE_HASHJOIN to OFF, I get:
QUERY PLAN
Merge Join (cost=0.31..195.66 rows=2260 width=16)
Merge Cond: (t1.id=t2.id)
-> Unique (cost=0.15..83.71 rows=2260 width=8)
-> Index Scan using t1_pkey on t1 (cost=0.15..78.06 rows=2260 width=8)
-> Index Scan using t2_pkey on t2 (cost=0.15..78.06 rows=2260 width=8)
I may be missing something, but this looks like a bug.
I'm using PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-12), 64-bit on AWS RDS.
The text was updated successfully, but these errors were encountered:
I could not get some hint to work a bigger query and narrowed the issue to this pattern:
Without the DISTINCT ON, the hints work fine:
Using
ANY_subquery
does not workMerge joins are possible, if I set
ENABLE_HASHJOIN
to OFF, I get:I may be missing something, but this looks like a bug.
I'm using
PostgreSQL 16.2 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 7.3.1 20180712 (Red Hat 7.3.1-12), 64-bit
on AWS RDS.The text was updated successfully, but these errors were encountered: