Access to Row ID information in Functions

From: "Paul Ramsey" <pramsey(at)cleverelephant(dot)ca>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Access to Row ID information in Functions
Date: 2008-04-01 18:37:40
Message-ID: 30fe546d0804011137k3e0895c6i42b60e050ddfd21d@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

In PostGIS, we have a problem, in that spatial operations are very
costly, CPUwise.

We have hit on a nifty enhancement recently, which was to recognize
that when processing multiple rows, in joins or with literal
argouments, for most functions of the form GeometryOperation(A, B), A
(or B) tended to remain constant, while the other argument changed.
That meant that we could build an "optimized" form of the
more-constant argument (using internal index structures on the object
segments) that allows testing the changing argument much more quickly.

The "optimized" form gets cached and retrieved from a memory context.
Each time the function is run within a statement it checks the cache,
and sees if one of its arguments are the same as the last time around.
If so, it uses the prepared version of that argument. If not, it
builds a new prepared version and caches that.

The key here is being able to check the identify of the arguments...
is this argument A the same as the one we processed last time? One way
is to do a memcmp. But it seems likely that PgSQL knows exactly
whether it is running a nested loop, or a literal, and could tell
somehow that argument A is the same with each call.

For lack of a better term, if we knew what the "row id" of each
argument was as the function was called, we could skip the memcmp
testing of geometric identity (which gets more expensive precisely at
the time our optimization gets more effective, for large arguments)
and just trust the row id as the guide of when to build and cache new
"optimized" representations.

Any guidance?

Thanks,

Paul

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2008-04-01 19:03:18 Re: Improve shutdown during online backup
Previous Message Aidan Van Dyk 2008-04-01 18:20:39 Re: Several tags around PostgreSQL 7.1 broken