Re: Re: GIST question - Mailing list pgsql-patches

From Bruce Momjian
Subject Re: Re: GIST question
Date
Msg-id 200105152150.f4FLojh06845@candle.pha.pa.us
Whole thread Raw
In response to Re: Re: GIST question  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Re: GIST question  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-patches
> Bruce Momjian <pgman@candle.pha.pa.us> writes:
> > Do you have any idea why you used the column in the GIST code?
>
> Its use in GiST is ancient ... Oleg didn't add it.

OK, I propose the following patch to remove pg_index.indhaskeytype.

The value was always TRUE, so the GIST tests are removed so the code is
always run.  Regression runs fine.

I will keep the patch for a day and apply it if no one objects.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
Index: src/backend/access/gist/gist.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/access/gist/gist.c,v
retrieving revision 1.76
diff -c -r1.76 gist.c
*** src/backend/access/gist/gist.c    2001/05/15 14:14:49    1.76
--- src/backend/access/gist/gist.c    2001/05/15 21:44:39
***************
*** 1127,1151 ****
          elog(ERROR, "initGISTstate: index %u not found",
               RelationGetRelid(index));
      itupform = (Form_pg_index) GETSTRUCT(htup);
-     giststate->haskeytype = itupform->indhaskeytype;
      indexrelid = itupform->indexrelid;
      ReleaseSysCache(htup);

!     if (giststate->haskeytype)
!     {
!         /* key type is different -- is it byval? */
!         htup = SearchSysCache(ATTNUM,
!                               ObjectIdGetDatum(indexrelid),
!                               UInt16GetDatum(FirstOffsetNumber),
!                               0, 0);
!         if (!HeapTupleIsValid(htup))
!             elog(ERROR, "initGISTstate: no attribute tuple %u %d",
!                  indexrelid, FirstOffsetNumber);
!         giststate->keytypbyval = (((Form_pg_attribute) htup)->attbyval);
!         ReleaseSysCache(htup);
!     }
!     else
!         giststate->keytypbyval = FALSE;
  }


--- 1127,1145 ----
          elog(ERROR, "initGISTstate: index %u not found",
               RelationGetRelid(index));
      itupform = (Form_pg_index) GETSTRUCT(htup);
      indexrelid = itupform->indexrelid;
      ReleaseSysCache(htup);

!     /* Is it byval? */
!     htup = SearchSysCache(ATTNUM,
!                           ObjectIdGetDatum(indexrelid),
!                           UInt16GetDatum(FirstOffsetNumber),
!                           0, 0);
!     if (!HeapTupleIsValid(htup))
!         elog(ERROR, "initGISTstate: no attribute tuple %u %d",
!              indexrelid, FirstOffsetNumber);
!     giststate->keytypbyval = (((Form_pg_attribute) htup)->attbyval);
!     ReleaseSysCache(htup);
  }


***************
*** 1197,1215 ****
      GISTENTRY  *dep;

      gistentryinit(*e, pr, r, pg, o, b, l);
!     if (giststate->haskeytype)
!     {
!         if ( b ) {
!             dep = (GISTENTRY *)
!                 DatumGetPointer(FunctionCall1(&giststate->decompressFn,
!                                           PointerGetDatum(e)));
!             gistentryinit(*e, dep->pred, dep->rel, dep->page, dep->offset, dep->bytes,
!                       dep->leafkey);
!             if (dep != e)
!                 pfree(dep);
!         } else {
!             gistentryinit(*e, (char*)NULL, r, pg, o, 0, l);
!         }
      }
  }

--- 1191,1206 ----
      GISTENTRY  *dep;

      gistentryinit(*e, pr, r, pg, o, b, l);
!     if ( b ) {
!         dep = (GISTENTRY *)
!             DatumGetPointer(FunctionCall1(&giststate->decompressFn,
!                                       PointerGetDatum(e)));
!         gistentryinit(*e, dep->pred, dep->rel, dep->page, dep->offset, dep->bytes,
!                   dep->leafkey);
!         if (dep != e)
!             pfree(dep);
!     } else {
!         gistentryinit(*e, (char*)NULL, r, pg, o, 0, l);
      }
  }

***************
*** 1224,1239 ****
      GISTENTRY  *cep;

      gistentryinit(*e, pr, r, pg, o, b, l);
!     if (giststate->haskeytype)
!     {
!         cep = (GISTENTRY *)
!             DatumGetPointer(FunctionCall1(&giststate->compressFn,
!                                           PointerGetDatum(e)));
!         gistentryinit(*e, cep->pred, cep->rel, cep->page, cep->offset, cep->bytes,
!                       cep->leafkey);
!         if (cep != e)
!             pfree(cep);
!     }
  }

  #ifdef GISTDEBUG
--- 1215,1227 ----
      GISTENTRY  *cep;

      gistentryinit(*e, pr, r, pg, o, b, l);
!     cep = (GISTENTRY *)
!         DatumGetPointer(FunctionCall1(&giststate->compressFn,
!                                       PointerGetDatum(e)));
!     gistentryinit(*e, cep->pred, cep->rel, cep->page, cep->offset, cep->bytes,
!                   cep->leafkey);
!     if (cep != e)
!         pfree(cep);
  }

  #ifdef GISTDEBUG
Index: src/backend/catalog/index.c
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/backend/catalog/index.c,v
retrieving revision 1.149
diff -c -r1.149 index.c
*** src/backend/catalog/index.c    2001/05/15 03:49:34    1.149
--- src/backend/catalog/index.c    2001/05/15 21:44:44
***************
*** 589,595 ****
      indexForm->indproc = indexInfo->ii_FuncOid;
      indexForm->indisclustered = false;            /* not used */
      indexForm->indislossy = islossy;
-     indexForm->indhaskeytype = true;            /* used by GIST */
      indexForm->indisunique = indexInfo->ii_Unique;
      indexForm->indisprimary = primary;
      memcpy((char *) &indexForm->indpred, (char *) predText, predLen);
--- 589,594 ----
Index: src/include/access/gist.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/access/gist.h,v
retrieving revision 1.26
diff -c -r1.26 gist.h
*** src/include/access/gist.h    2001/03/22 04:00:26    1.26
--- src/include/access/gist.h    2001/05/15 21:44:46
***************
*** 74,80 ****
      FmgrInfo    penaltyFn;
      FmgrInfo    picksplitFn;
      FmgrInfo    equalFn;
-     bool        haskeytype;
      bool        keytypbyval;
  } GISTSTATE;

--- 74,79 ----
Index: src/include/catalog/catversion.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/catalog/catversion.h,v
retrieving revision 1.78
diff -c -r1.78 catversion.h
*** src/include/catalog/catversion.h    2001/05/15 03:49:35    1.78
--- src/include/catalog/catversion.h    2001/05/15 21:44:46
***************
*** 53,58 ****
   */

  /*                            yyyymmddN */
! #define CATALOG_VERSION_NO    200105145

  #endif
--- 53,58 ----
   */

  /*                            yyyymmddN */
! #define CATALOG_VERSION_NO    200105151

  #endif
Index: src/include/catalog/pg_index.h
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/include/catalog/pg_index.h,v
retrieving revision 1.19
diff -c -r1.19 pg_index.h
*** src/include/catalog/pg_index.h    2001/05/15 03:49:35    1.19
--- src/include/catalog/pg_index.h    2001/05/15 21:44:46
***************
*** 37,44 ****
  /*
   * it seems that all variable length fields should go at the _end_,
   * because the system cache routines only copy the fields up to the
!  * first variable length field.  so I moved indislossy, indhaskeytype,
!  * and indisunique before indpred.    --djm 8/20/96
   */
  CATALOG(pg_index)
  {
--- 37,44 ----
  /*
   * it seems that all variable length fields should go at the _end_,
   * because the system cache routines only copy the fields up to the
!  * first variable length field.  so I moved indislossy and indisunique
!  * before indpred.    --djm 8/20/96
   */
  CATALOG(pg_index)
  {
***************
*** 54,60 ****
                                   */
      bool        indislossy;        /* do we fetch false tuples (lossy
                                   * compression)? */
-     bool        indhaskeytype;    /* does key type != attribute type? */
      bool        indisunique;    /* is this a unique index? */
      bool        indisprimary;    /* is this index for primary key */
      Oid            indreference;    /* oid of index of referenced relation (ie
--- 54,59 ----
***************
*** 73,79 ****
   *        compiler constants for pg_index
   * ----------------
   */
! #define Natts_pg_index                    12
  #define Anum_pg_index_indexrelid        1
  #define Anum_pg_index_indrelid            2
  #define Anum_pg_index_indproc            3
--- 72,78 ----
   *        compiler constants for pg_index
   * ----------------
   */
! #define Natts_pg_index                    11
  #define Anum_pg_index_indexrelid        1
  #define Anum_pg_index_indrelid            2
  #define Anum_pg_index_indproc            3
***************
*** 81,90 ****
  #define Anum_pg_index_indclass            5
  #define Anum_pg_index_indisclustered    6
  #define Anum_pg_index_indislossy        7
! #define Anum_pg_index_indhaskeytype        8
! #define Anum_pg_index_indisunique        9
! #define Anum_pg_index_indisprimary        10
! #define Anum_pg_index_indreference        11
! #define Anum_pg_index_indpred            12

  #endif     /* PG_INDEX_H */
--- 80,88 ----
  #define Anum_pg_index_indclass            5
  #define Anum_pg_index_indisclustered    6
  #define Anum_pg_index_indislossy        7
! #define Anum_pg_index_indisunique        8
! #define Anum_pg_index_indisprimary        9
! #define Anum_pg_index_indreference        10
! #define Anum_pg_index_indpred            11

  #endif     /* PG_INDEX_H */
Index: src/test/regress/expected/opr_sanity.out
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/test/regress/expected/opr_sanity.out,v
retrieving revision 1.26
diff -c -r1.26 opr_sanity.out
*** src/test/regress/expected/opr_sanity.out    2001/05/15 04:12:56    1.26
--- src/test/regress/expected/opr_sanity.out    2001/05/15 21:44:53
***************
*** 482,489 ****
            (p2.pronargs = 1 AND p1.aggbasetype = 0)));
    oid  | aggname | oid |   proname
  -------+---------+-----+-------------
!  17009 | max     | 768 | int4larger
!  17023 | min     | 769 | int4smaller
  (2 rows)

  -- Cross-check finalfn (if present) against its entry in pg_proc.
--- 482,489 ----
            (p2.pronargs = 1 AND p1.aggbasetype = 0)));
    oid  | aggname | oid |   proname
  -------+---------+-----+-------------
!  17008 | max     | 768 | int4larger
!  17022 | min     | 769 | int4smaller
  (2 rows)

  -- Cross-check finalfn (if present) against its entry in pg_proc.

pgsql-patches by date:

Previous
From: Bruce Momjian
Date:
Subject: Fix for SQLStatistics
Next
From: Tom Lane
Date:
Subject: Re: Re: GIST question