On Thu, 06 Jan 2022 at 00:34, Tom Lane <t...@sss.pgh.pa.us> wrote: > Japin Li <japi...@hotmail.com> writes: >> Here is a patch for POC testing. > > This is certainly not right. You've made gbt_bpchar_consistent > work identically to gbt_text_consistent, but it needs to implement > a test equivalent to bpchareq, ie ignore trailing spaces in both > inputs. >
Thanks for your explaintion! The bpchareq already ignore trailing spaces in both inputs. The question is that the bpchar in btree_gist do not call bpchareq, it always call texteq. I tried the patch[1] and it works as expected, howerver, I don't think it's good way to fix this problem. > 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. Am I understand right? -- Regrads, Japin Li. ChengDu WenWu Information Technology Co.,Ltd. [1] diff --git a/contrib/btree_gist/btree_text.c b/contrib/btree_gist/btree_text.c index 8019d11281..7f45ee6e3b 100644 --- a/contrib/btree_gist/btree_text.c +++ b/contrib/btree_gist/btree_text.c @@ -121,16 +121,7 @@ gbt_bpchar_compress(PG_FUNCTION_ARGS) } if (entry->leafkey) - { - - Datum d = DirectFunctionCall1(rtrim1, entry->key); - GISTENTRY trim; - - gistentryinit(trim, d, - entry->rel, entry->page, - entry->offset, true); - retval = gbt_var_compress(&trim, &tinfo); - } + retval = gbt_var_compress(entry, &tinfo); else retval = entry; @@ -189,6 +180,11 @@ gbt_bpchar_consistent(PG_FUNCTION_ARGS) tinfo.eml = pg_database_encoding_max_length(); } + r.lower = (bytea *) DatumGetPointer(DirectFunctionCall1(rtrim1, + PointerGetDatum(r.lower))); + r.upper = (bytea *) DatumGetPointer(DirectFunctionCall1(rtrim1, + PointerGetDatum(r.upper))); + retval = gbt_var_consistent(&r, trim, strategy, PG_GET_COLLATION(), GIST_LEAF(entry), &tinfo, fcinfo->flinfo); PG_RETURN_BOOL(retval);