Re: Index-only scan for btree_gist turns bpchar to char
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Japin Li <japinli@hotmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>, pgsql-hackers@lists.postgresql.org
Date: 2022-01-06T19:21:15Z
Lists: pgsql-hackers
Attachments
- fix-btree_gist-bpchar-trimming.patch (text/x-diff) patch
Japin Li <japinli@hotmail.com> writes: > On Thu, 06 Jan 2022 at 00:34, Tom Lane <tgl@sss.pgh.pa.us> wrote: >> The minimum-effort fix would be to apply rtrim1 to both strings >> in gbt_bpchar_consistent, but I wonder if we can improve on that >> by pushing the ignore-trailing-spaces behavior further down. >> I didn't look yet at whether gbt_var_consistent can support >> any type-specific behavior. > Adding type-specific for gbt_var_consistent looks like more generally. > For example, for bpchar type, we should call bpchareq rather than texteq. I looked at this and it does seem like it might work, as per attached patch. The one thing that is troubling me is that the opclass is set up to apply gbt_text_same, which is formally the Wrong Thing for bpchar, because the equality semantics shouldn't be quite the same. But we could not fix that without a module version bump, which is annoying. I think that it might not be necessary to change it, because (1) There's no such thing as unique GIST indexes, so it should not matter if the "same" function is a bit stricter than the datatype's nominal notion of equality. It's certainly okay for that to vary from the semantics applied by the consistent function --- GIST has no idea that the consistent function is allegedly testing equality. (2) If all the input values for a column have been coerced to the same typmod, then it doesn't matter because two values that are equal after space-stripping would be equal without space-stripping, too. However, (2) doesn't hold for an existing index that the user has failed to REINDEX, because then the index would contain some space-stripped values that same() will not say are equal to incoming new values. Again, I think this doesn't matter much, but maybe I'm missing something. I've not really dug into what GIST uses the same() function for. In any case, if we do need same() to implement the identical behavior to bpchareq(), then the other solution isn't sufficient either. So in short, it seems like we ought to do some compatibility testing and see if this code misbehaves at all with an index created by the old code. I don't particularly want to do that ... any volunteers? regards, tom lane
Commits
-
Fix results of index-only scans on btree_gist char(N) indexes.
- b2198690847f 10.20 landed
- 823d4c7e2538 13.6 landed
- 54b1cb7eb784 15.0 landed
- 3a69d45afcc8 12.10 landed
- 38cbdd22d633 11.15 landed
- 043c1e1a73aa 14.2 landed