indexable and locale - Mailing list pgsql-hackers

From Goran Thyni
Subject indexable and locale
Date
Msg-id 38076E23.DF48EB24@kirra.net
Whole thread Raw
Responses Re: [HACKERS] indexable and locale
Re: indexable and locale
Re: indexable and locale
List pgsql-hackers
Hello again,
I thought I should start making some small contibutions before 7.0.

Attached is a patch to the old problem discussed feverly before 6.5.
What is does:
for locale-enabled servers:
    use index if last char before '%' is ascii.
for non-locale servers:
    do not use locale if last char is non-ascii since it is wrong anyway.

Comments?

regards,
--
-----------------
Göran Thyni
On quiet nights you can hear Windows NT reboot!diff -c pgsql/src/backend/optimizer/path/indxpath.c
work/pgsql/src/backend/optimizer/path/indxpath.c
*** pgsql/src/backend/optimizer/path/indxpath.c    Wed Oct  6 18:33:57 1999
--- work/pgsql/src/backend/optimizer/path/indxpath.c    Fri Oct 15 19:54:34 1999
***************
*** 1934,1968 ****
      op = makeOper(optup->t_data->t_oid, InvalidOid, BOOLOID, 0, NULL);
      expr = make_opclause(op, leftop, (Var *) con);
      result = lcons(expr, NIL);
-
      /*
!      * In ASCII locale we say "x <= prefix\377".  This does not
!      * work for non-ASCII collation orders, and it's not really
!      * right even for ASCII.  FIX ME!
!      * Note we assume the passed prefix string is workspace with
!      * an extra byte, as created by the xxx_fixed_prefix routines above.
       */
! #ifndef USE_LOCALE
!     prefixlen = strlen(prefix);
!     prefix[prefixlen] = '\377';
!     prefix[prefixlen+1] = '\0';
!
!     optup = SearchSysCacheTuple(OPRNAME,
!                                 PointerGetDatum("<="),
!                                 ObjectIdGetDatum(datatype),
!                                 ObjectIdGetDatum(datatype),
!                                 CharGetDatum('b'));
!     if (!HeapTupleIsValid(optup))
!         elog(ERROR, "prefix_quals: no <= operator for type %u", datatype);
!     conval = (datatype == NAMEOID) ?
!         (void*) namein(prefix) : (void*) textin(prefix);
!     con = makeConst(datatype, ((datatype == NAMEOID) ? NAMEDATALEN : -1),
!                     PointerGetDatum(conval),
!                     false, false, false, false);
!     op = makeOper(optup->t_data->t_oid, InvalidOid, BOOLOID, 0, NULL);
!     expr = make_opclause(op, leftop, (Var *) con);
!     result = lappend(result, expr);
! #endif
!
      return result;
  }
--- 1934,1970 ----
      op = makeOper(optup->t_data->t_oid, InvalidOid, BOOLOID, 0, NULL);
      expr = make_opclause(op, leftop, (Var *) con);
      result = lcons(expr, NIL);
      /*
!      * If last is in ascii range make it indexable,
!      * else let it be.
!      * FIXME: find way to use locate for this to support
!      *        indexing of non-ascii characters.
       */
!     prefixlen = strlen(prefix) - 1;
!     elog(DEBUG, "XXX1 %s", prefix);
!     if ((unsigned) prefix[prefixlen] < 126)
!       {
!         prefix[prefixlen]++;
!         elog(DEBUG, "XXX2 %s", prefix);
!         optup = SearchSysCacheTuple(OPRNAME,
!                     PointerGetDatum("<="),
!                     ObjectIdGetDatum(datatype),
!                     ObjectIdGetDatum(datatype),
!                     CharGetDatum('b'));
!         if (!HeapTupleIsValid(optup))
!           elog(ERROR, "prefix_quals: no <= operator for type %u", datatype);
!         conval = (datatype == NAMEOID) ?
!           (void*) namein(prefix) : (void*) textin(prefix);
!         con = makeConst(datatype, ((datatype == NAMEOID) ? NAMEDATALEN : -1),
!                 PointerGetDatum(conval),
!                 false, false, false, false);
!         op = makeOper(optup->t_data->t_oid, InvalidOid, BOOLOID, 0, NULL);
!         expr = make_opclause(op, leftop, (Var *) con);
!         result = lappend(result, expr);
!       }
      return result;
  }

Attachment

pgsql-hackers by date:

Previous
From: wieck@debis.com (Jan Wieck)
Date:
Subject: Re: [HACKERS] The new globe
Next
From: Oleg Bartunov
Date:
Subject: vacuum of permanently updating database