Re: [BUGS] BUG #11500: PRIMARY KEY index not being used
От | Tom Lane |
---|---|
Тема | Re: [BUGS] BUG #11500: PRIMARY KEY index not being used |
Дата | |
Msg-id | 1704045.1759687759@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: [BUGS] BUG #11500: PRIMARY KEY index not being used (Marko Tiikkaja <marko@joh.to>) |
Ответы |
Re: [BUGS] BUG #11500: PRIMARY KEY index not being used
|
Список | pgsql-bugs |
Marko Tiikkaja <marko@joh.to> writes: > I can't believe I actually have to do this, but run: That's not what was asked for. Your original report showed a case where the planner chose orders_wait_event_idx despite estimating that it would have to scan 80K-plus rows. That's the case where I don't understand how it could think that the primary key index would be even more expensive. I'm not particularly concerned about the case you show here, because if you run the EXPLAIN a second time it gets a lot cheaper. I believe the reason is that the first time is visiting a bunch of just-deleted rows and so it has to stop and update their hint bits, both in the heap and the index. That is not a cost that the planner can reasonably predict in advance, and even if we could it's not really fair to blame it on the choice of index. The pkey alternative only visits one row and therefore only updates one hint bit, but we'd have to update the rest sooner or later. So IMO the speed difference is largely illusory because it arises from deferring maintenance. You can demonstrate this by changing the "ANALYZE orders" in the test case to "VACUUM ANALYZE orders": the EXPLAIN still chooses orders_wait_event_idx, but now it's fast because all that work got done by VACUUM. regards, tom lane
В списке pgsql-bugs по дате отправления: