ossc-db / pg_hint_plan

Extension adding support for optimizer hints in PostgreSQL
Other
696 stars 103 forks source link

rows hint does not work as expected #127

Closed nikulinas closed 1 year ago

nikulinas commented 1 year ago

I am testing hint rows and could not make it work. Looks like hint affects only estimated rows parameter, not join method (unlike cardinality in Oracle)

alex=#  explain /*+ rows(t1 t2 #13)*/SELECT * FROM t1 t1 JOIN t2 t2 ON t1.id = t2.id;
                              QUERY PLAN
-----------------------------------------------------------------------
 Hash Join  (cost=3280.02..7663.05 rows=13 width=26)
   Hash Cond: (t1.id = t2.id)
   ->  Seq Scan on t1  (cost=0.00..1541.01 rows=100001 width=13)
   ->  Hash  (cost=1541.01..1541.01 rows=100001 width=13)
         ->  Seq Scan on t2  (cost=0.00..1541.01 rows=100001 width=13)
(5 rows)

The following investigations showed that costs of different method of join are defined by estimeted rows number of joined tables, not estimeted rows number of join result (see initial_cost_nestloop, final_cost_nestloop, initial_cost_mergejoin, final_cost_mergejoin, initial_cost_hashjoin, final_cost_hashjoin in src/backend/optimizer/path/costsize.c )

michaelpq commented 1 year ago

Hmm. I am not sure that this is a bug. From what I can see the hint behaves as documented: the row estimation is changed in the outer join.

If you think that a different behavior would make more sense, why not sending a patch?