diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2007-01-09 02:14:16 +0000 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2007-01-09 02:14:16 +0000 |
commit | 443175822942ef1f15cd047cda58990a089ef180 (patch) | |
tree | a5e4272719d3323d9aa17312d0d867804b652f10 /src/backend/utils/cache/relcache.c | |
parent | 3a32ba2f3f54378e3e06366a5ff06e339984f065 (diff) | |
download | postgresql-443175822942ef1f15cd047cda58990a089ef180.tar.gz postgresql-443175822942ef1f15cd047cda58990a089ef180.zip |
Support ORDER BY ... NULLS FIRST/LAST, and add ASC/DESC/NULLS FIRST/NULLS LAST
per-column options for btree indexes. The planner's support for this is still
pretty rudimentary; it does not yet know how to plan mergejoins with
nondefault ordering options. The documentation is pretty rudimentary, too.
I'll work on improving that stuff later.
Note incompatible change from prior behavior: ORDER BY ... USING will now be
rejected if the operator is not a less-than or greater-than member of some
btree opclass. This prevents less-than-sane behavior if an operator that
doesn't actually define a proper sort ordering is selected.
Diffstat (limited to 'src/backend/utils/cache/relcache.c')
-rw-r--r-- | src/backend/utils/cache/relcache.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index baa45447a29..c43846cd57a 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.253 2007/01/05 22:19:43 momjian Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.254 2007/01/09 02:14:15 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -925,8 +925,10 @@ RelationInitIndexAccessInfo(Relation relation) HeapTuple tuple; Form_pg_am aform; Datum indclassDatum; + Datum indoptionDatum; bool isnull; oidvector *indclass; + int2vector *indoption; MemoryContext indexcxt; MemoryContext oldcontext; int natts; @@ -1019,6 +1021,9 @@ RelationInitIndexAccessInfo(Relation relation) relation->rd_supportinfo = NULL; } + relation->rd_indoption = (int16 *) + MemoryContextAllocZero(indexcxt, natts * sizeof(int16)); + /* * indclass cannot be referenced directly through the C struct, because it * comes after the variable-width indkey field. Must extract the @@ -1042,6 +1047,17 @@ RelationInitIndexAccessInfo(Relation relation) amstrategies, amsupport, natts); /* + * Similarly extract indoption and copy it to the cache entry + */ + indoptionDatum = fastgetattr(relation->rd_indextuple, + Anum_pg_index_indoption, + GetPgIndexDescriptor(), + &isnull); + Assert(!isnull); + indoption = (int2vector *) DatumGetPointer(indoptionDatum); + memcpy(relation->rd_indoption, indoption->values, natts * sizeof(int16)); + + /* * expressions and predicate cache will be filled later */ relation->rd_indexprs = NIL; @@ -3237,6 +3253,7 @@ load_relcache_init_file(void) Oid *operator; RegProcedure *support; int nsupport; + int16 *indoption; /* Count nailed indexes to ensure we have 'em all */ if (rel->rd_isnailed) @@ -3304,7 +3321,7 @@ load_relcache_init_file(void) rel->rd_operator = operator; - /* finally, read the vector of support procedures */ + /* next, read the vector of support procedures */ if ((nread = fread(&len, 1, sizeof(len), fp)) != sizeof(len)) goto read_failed; support = (RegProcedure *) MemoryContextAlloc(indexcxt, len); @@ -3313,6 +3330,16 @@ load_relcache_init_file(void) rel->rd_support = support; + /* finally, read the vector of indoption values */ + if ((nread = fread(&len, 1, sizeof(len), fp)) != sizeof(len)) + goto read_failed; + + indoption = (int16 *) MemoryContextAlloc(indexcxt, len); + if ((nread = fread(indoption, 1, len, fp)) != len) + goto read_failed; + + rel->rd_indoption = indoption; + /* set up zeroed fmgr-info vectors */ rel->rd_aminfo = (RelationAmInfo *) MemoryContextAllocZero(indexcxt, sizeof(RelationAmInfo)); @@ -3336,6 +3363,7 @@ load_relcache_init_file(void) Assert(rel->rd_operator == NULL); Assert(rel->rd_support == NULL); Assert(rel->rd_supportinfo == NULL); + Assert(rel->rd_indoption == NULL); } /* @@ -3525,10 +3553,15 @@ write_relcache_init_file(void) relform->relnatts * (am->amstrategies * sizeof(Oid)), fp); - /* finally, write the vector of support procedures */ + /* next, write the vector of support procedures */ write_item(rel->rd_support, relform->relnatts * (am->amsupport * sizeof(RegProcedure)), fp); + + /* finally, write the vector of indoption values */ + write_item(rel->rd_indoption, + relform->relnatts * sizeof(int16), + fp); } /* also make a list of their OIDs, for RelationIdIsInInitFile */ |