Re: Use of additional index columns in rows filtering
От | Tomas Vondra |
---|---|
Тема | Re: Use of additional index columns in rows filtering |
Дата | |
Msg-id | 744d49aa-9190-a51a-abff-59fa4d8b9970@enterprisedb.com обсуждение исходный текст |
Ответ на | Re: Use of additional index columns in rows filtering (Tomas Vondra <tomas.vondra@enterprisedb.com>) |
Ответы |
Re: Use of additional index columns in rows filtering
|
Список | pgsql-hackers |
On 7/15/23 16:20, Tomas Vondra wrote: > > ... > > 4) problems with opcintype != opckeytype (name_ops) > > While running the tests, I ran into an issue with name_ops, causing > failures for \dT and other catalog queries. The root cause is that > name_ops has opcintype = name, but opckeytype = cstring. The index-only > clauses are copied from the table, with Vars mutated to reference the > INDEX_VAR. But the type is not, so when we get to evaluating the > expressions, CheckVarSlotCompatibility() fails because the Var has name, > but the iss_IndexSlot (created with index tuple descriptor) has cstring. > > The rebased patch fixes this by explicitly adjusting types of the > descriptor in ExecInitIndexScan(). > > However, maybe this indicates the very idea of evaluating expressions > using slot with index tuple descriptor is misguided. This made me look > at regular index-only scan (nodeIndexonlyscan.c), and that uses a slot > with the "table" structure, and instead of evaluating the expression on > the index index tuple it expands the index tuple into the table slot. > Which is what StoreIndexTuple() does. > > So maybe this should do what IOS does - expand the index tuple into > "table slot" and evaluate the expression on that. That'd also make the > INDEX_VAR tweak in createplan.c unnecessary - in fact, that seemed a bit > strange anyway, so ditching fix_indexfilter_mutator would be good. > This kept bothering me, so I looked at it today, and reworked it to use the IOS approach. It's a bit more complicated because for IOS both slots have the same overall structure, except for the data types. But for regular index scans that's not the case - the code has to "expand" the index tuple into the larger "table slot". This works, and in general I think the result is much cleaner - in particular, it means we don't need to switch the Var nodes to reference the INDEX_VAR. While experimenting with this I realized again that we're not matching expressions to IOS. So if you have an expression index on (a+b), that can't be used even if the query only uses this particular expression. The same limitation applies to index-only filters, of course. It's not the fault of this patch, but perhaps it'd be an interesting improvement. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company
Вложения
В списке pgsql-hackers по дате отправления: