Tighten up btree_gist's handling of truncated bounds.

Truncating an internal node's upper bound can cause it to compare
less than some values that in fact are included in the represented
leaf page.  So we need a hack to make sure it looks large enough
to include all values that could be on the page.  But there's no
equivalent issue for the lower bound.  The fact that the code did
fuzzy comparisons for the lower bound too seems to be the result of
fuzzy thinking.  Or maybe there was a desire to not assume too much
about what the datatype's comparison rule is; but we've already
fully bought into the premise that internal keys compare like bytea.

Hence, remove the useless check against the key's lower bound in
gbt_var_node_pf_match.  The comparable check in gbt_var_penalty may
also be useless, but I'm not quite sure.  In any case that seems
negligible from a performance standpoint, so I left it alone.

Also, in the strategy cases in gbt_var_consistent that only
require comparisons to the lower bound, there's no need to call
gbt_var_node_pf_match at all.  Refactor that logic by inventing
macros lower_is_below_query and upper_is_above_query to directly
express what we need to test.  I also took this opportunity to flip
all the tests around to be "indexkey OP query" rather than mostly
being the reverse: IMO this makes the code less confusing since the
tests now match the names of the strategies.

Also, in the name of consistency, make gbt_num_consistent look
like that too.  There's no functional change there, but this
should be more readable going forward.

Author: Tom Lane <[email protected]>
Reviewed-by: Ayush Tiwari <[email protected]>
Discussion: 
https://postgr.es/m/AH*avqcykhqgvvpwi1giu4oy.8.1781609375063.hmail.3020001...@tju.edu.cn

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/fea9c1884b2009a94287989e961d6493e22bf656

Modified Files
--------------
contrib/btree_gist/btree_utils_num.c | 45 ++++++++++++++++++-------
contrib/btree_gist/btree_utils_var.c | 64 +++++++++++++++++++-----------------
2 files changed, 67 insertions(+), 42 deletions(-)

Reply via email to