diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-12-02 20:50:48 -0500 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-12-02 20:51:37 -0500 |
commit | d583f10b7e0b9e1ed18f339f3177ed42ac2f7570 (patch) | |
tree | dab8027658ca6bf21b0199c15c5f775578d645c9 /src/backend/access/gist/gistscan.c | |
parent | d7e5d151daa2d5fe096953ae0b3530707b7c87f5 (diff) | |
download | postgresql-d583f10b7e0b9e1ed18f339f3177ed42ac2f7570.tar.gz postgresql-d583f10b7e0b9e1ed18f339f3177ed42ac2f7570.zip |
Create core infrastructure for KNNGIST.
This is a heavily revised version of builtin_knngist_core-0.9. The
ordering operators are no longer mixed in with actual quals, which would
have confused not only humans but significant parts of the planner.
Instead, ordering operators are carried separately throughout planning and
execution.
Since the API for ambeginscan and amrescan functions had to be changed
anyway, this commit takes the opportunity to rationalize that a bit.
RelationGetIndexScan no longer forces a premature index_rescan call;
instead, callers of index_beginscan must call index_rescan too. Aside from
making the AM-side initialization logic a bit less peculiar, this has the
advantage that we do not make a useless extra am_rescan call when there are
runtime key values. AMs formerly could not assume that the key values
passed to amrescan were actually valid; now they can.
Teodor Sigaev and Tom Lane
Diffstat (limited to 'src/backend/access/gist/gistscan.c')
-rw-r--r-- | src/backend/access/gist/gistscan.c | 74 |
1 files changed, 34 insertions, 40 deletions
diff --git a/src/backend/access/gist/gistscan.c b/src/backend/access/gist/gistscan.c index 21f4ea54b7d..106714511a8 100644 --- a/src/backend/access/gist/gistscan.c +++ b/src/backend/access/gist/gistscan.c @@ -28,10 +28,24 @@ gistbeginscan(PG_FUNCTION_ARGS) { Relation r = (Relation) PG_GETARG_POINTER(0); int nkeys = PG_GETARG_INT32(1); - ScanKey key = (ScanKey) PG_GETARG_POINTER(2); + int norderbys = PG_GETARG_INT32(2); IndexScanDesc scan; + GISTScanOpaque so; + + /* no order by operators allowed */ + Assert(norderbys == 0); + + scan = RelationGetIndexScan(r, nkeys, norderbys); + + /* initialize opaque data */ + so = (GISTScanOpaque) palloc(sizeof(GISTScanOpaqueData)); + so->stack = NULL; + so->tempCxt = createTempGistContext(); + so->curbuf = InvalidBuffer; + so->giststate = (GISTSTATE *) palloc(sizeof(GISTSTATE)); + initGISTstate(so->giststate, scan->indexRelation); - scan = RelationGetIndexScan(r, nkeys, key); + scan->opaque = so; PG_RETURN_POINTER(scan); } @@ -41,33 +55,18 @@ gistrescan(PG_FUNCTION_ARGS) { IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0); ScanKey key = (ScanKey) PG_GETARG_POINTER(1); - GISTScanOpaque so; + /* remaining arguments are ignored */ + GISTScanOpaque so = (GISTScanOpaque) scan->opaque; int i; - so = (GISTScanOpaque) scan->opaque; - if (so != NULL) + /* rescan an existing indexscan --- reset state */ + gistfreestack(so->stack); + so->stack = NULL; + /* drop pins on buffers -- no locks held */ + if (BufferIsValid(so->curbuf)) { - /* rescan an existing indexscan --- reset state */ - gistfreestack(so->stack); - so->stack = NULL; - /* drop pins on buffers -- no locks held */ - if (BufferIsValid(so->curbuf)) - { - ReleaseBuffer(so->curbuf); - so->curbuf = InvalidBuffer; - } - } - else - { - /* initialize opaque data */ - so = (GISTScanOpaque) palloc(sizeof(GISTScanOpaqueData)); - so->stack = NULL; - so->tempCxt = createTempGistContext(); + ReleaseBuffer(so->curbuf); so->curbuf = InvalidBuffer; - so->giststate = (GISTSTATE *) palloc(sizeof(GISTSTATE)); - initGISTstate(so->giststate, scan->indexRelation); - - scan->opaque = so; } /* @@ -130,21 +129,16 @@ Datum gistendscan(PG_FUNCTION_ARGS) { IndexScanDesc scan = (IndexScanDesc) PG_GETARG_POINTER(0); - GISTScanOpaque so; - - so = (GISTScanOpaque) scan->opaque; - - if (so != NULL) - { - gistfreestack(so->stack); - if (so->giststate != NULL) - freeGISTstate(so->giststate); - /* drop pins on buffers -- we aren't holding any locks */ - if (BufferIsValid(so->curbuf)) - ReleaseBuffer(so->curbuf); - MemoryContextDelete(so->tempCxt); - pfree(scan->opaque); - } + GISTScanOpaque so = (GISTScanOpaque) scan->opaque; + + gistfreestack(so->stack); + if (so->giststate != NULL) + freeGISTstate(so->giststate); + /* drop pins on buffers -- we aren't holding any locks */ + if (BufferIsValid(so->curbuf)) + ReleaseBuffer(so->curbuf); + MemoryContextDelete(so->tempCxt); + pfree(so); PG_RETURN_VOID(); } |