Re: [GENERAL] Backwards index scan

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Dmitry Tkach <dmitry(at)openratings(dot)com>
Cc: pgsql-hackers(at)postgreSQL(dot)org
Subject: Re: [GENERAL] Backwards index scan
Date: 2003-07-14 18:34:57
Message-ID: 10413.1058207697@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general pgsql-hackers

[ reply redirected to a more appropriate list ]

Dmitry Tkach <dmitry(at)openratings(dot)com> writes:
> I am not sure if this is really a bug, but it certainly looks like one
> to me...

It's not a bug, but I agree that _bt_first can be inefficient if there
are lots of matching keys.

> This is because there are *lots* (a few million) of matches for x=10,
> and _bt_first () scans through them *all* sequentually to get to the
> last one.
> I understand that with the generic approach to operators in postgres it
> is, probably, not very feasible to try and teach _bt_first () to handle
> this situation automatically (it would need to know how to get
> next/previous value for every indexable type)...

I think what we'd want is variant versions of _bt_search and _bt_binsrch
that locate the first entry greater than the specified target key,
rather than the first entry greater than or equal to it. Given such
positioning, all the _bt_first cases that involve stepping over more
than one entry could be improved to require no more than one step.

Not sure whether it'd be better to make clone versions of these
functions, or to add a parameter to tell them which behavior is wanted.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Jefferies, Rupert 2003-07-15 10:14:39 createdb failure on version 7.3.3 with Solaris 9
Previous Message Tom Lane 2003-07-14 17:30:28 Re: segfault at aset.c:539

Browse pgsql-general by date

  From Date Subject
Next Message David Olbersen 2003-07-14 18:53:30 Reverse compatibility
Previous Message scott.marlowe 2003-07-14 16:41:18 Re: What is the max size for a bytea field?

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2003-07-14 20:05:57 Re: cvs version compile error on AIX 4.3.3 using xlc (long)
Previous Message Andreas Pflug 2003-07-14 16:18:03 Re: CVS notification (Path algorithms)