Re: Minimum selectivity estimate for LIKE 'prefix%' - Mailing list pgsql-patches

From Peter Eisentraut
Subject Re: Minimum selectivity estimate for LIKE 'prefix%'
Date
Msg-id 200803171710.41400.peter_e@gmx.net
Whole thread Raw
In response to Minimum selectivity estimate for LIKE 'prefix%'  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Minimum selectivity estimate for LIKE 'prefix%'  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
Am Donnerstag, 6. März 2008 schrieb Tom Lane:
> I attach a proposed patch against HEAD for this.  It's a bit long
> but most of the bulk is refactoring eqsel() to make it easy to use from
> prefix_selectivity().  The intellectual content is just in the last
> diff hunk.

Looking at the patch as committed here
<http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/utils/adt/selfuncs.c.diff?r1=1.243;r2=1.244>,
I am confused by one hunk:

*************** prefix_selectivity(VariableStatData *var
*** 4452,4468 ****
       *    "x < greaterstr".
       *-------
       */
-     cmpopr = get_opfamily_member(opfamily, vartype, vartype,
-                                  BTLessStrategyNumber);
-     if (cmpopr == InvalidOid)
-         elog(ERROR, "no < operator for opfamily %u", opfamily);
-     fmgr_info(get_opcode(cmpopr), &opproc);
-
      greaterstrcon = make_greater_string(prefixcon, &opproc);
      if (greaterstrcon)
      {
          Selectivity topsel;

          topsel = ineq_histogram_selectivity(vardata, &opproc, false,
                                              greaterstrcon->constvalue,
                                              greaterstrcon->consttype);
--- 4503,4519 ----
       *    "x < greaterstr".
       *-------
       */
      greaterstrcon = make_greater_string(prefixcon, &opproc);
      if (greaterstrcon)
      {
          Selectivity topsel;

+         cmpopr = get_opfamily_member(opfamily, vartype, vartype,
+                                      BTLessStrategyNumber);
+         if (cmpopr == InvalidOid)
+             elog(ERROR, "no < operator for opfamily %u", opfamily);
+         fmgr_info(get_opcode(cmpopr), &opproc);
+
          topsel = ineq_histogram_selectivity(vardata, &opproc, false,
                                              greaterstrcon->constvalue,
                                              greaterstrcon->consttype);

make_greater_string() is documented as

 * The caller must provide the appropriate "less than" comparison function
 * for testing the strings.

but using the new code flow it appears that opproc would still refer to
the >= operator looked up earlier.

The 8.1 code calls this variable ltproc because it didn't need the >= operator.
Perhaps using two variables would also be clearer here.

pgsql-patches by date:

Previous
From: KaiGai Kohei
Date:
Subject: Re: [HACKERS] [0/4] Proposal of SE-PostgreSQL patches
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] CIC and deadlocks