Re: Need theory/comprehension help on Multi-Column indexes

From: "Merlin Moncure" <merlin(dot)moncure(at)rcsonline(dot)com>
To: <josh(at)agliodbs(dot)com>
Cc: <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Need theory/comprehension help on Multi-Column indexes
Date: 2005-01-04 20:09:52
Message-ID: 6EE64EF3AB31D5448D0007DD34EEB3412A7590@Herge.rcsinc.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> Folks,
>
> I've been poking around the indexing code, and I really don't
understand
> the
> page structure and splittng/branching for multi-column BTree indexes.
> I've
> looked in a couple DB textbooks to get a theoretically underpinning of
the
> structure of multi-column indexes, but none of the ones I've seen
cover
> them.
> Can someone help me out?

Heh. You haven't done much programming in COBOL. The basic idea is to
combine the multiple fields in a sequence of bytes (reversible into the
original fields) and do a straight strcmp()
int c(6) n(2)
So you have key k on t(f1, f2, f3)
And do an insert to t(1, 'abc', 44)
The datum
******* **
"00000001 abc44" gets applied to the index. The values below the stars
are the lowest values supported by that particular type. The
requirement being that for a type to be indexible it must have able to
be mutated into a fixed length string.

At least, that is the simple way to do it. It is also possible to
create an index using discreet fields and the type's built in Boolean
comparison. This is more complicated, for example to find out if
t(a,b,c) > t(a1,b1,c1)
You have to check
a >= a1 and
(a > a1 or b >= b1) and
(a > a1 or b > b1 or c > c1)
or the Boolean reverse of the above:
a > a1 or
(a >= a1 and b > b1) or
(a >= a1 or b >= b1 or c > c1)

The above expression would have to be applied to generate a comparison
between an input value and a stored key value.
Merlin

Browse pgsql-hackers by date

  From Date Subject
Next Message Serguei A. Mokhov 2005-01-04 20:13:26 Re: [HACKERS] Final call for translation updates
Previous Message Devrim GUNDUZ 2005-01-04 20:03:45 Re: [HACKERS] Final call for translation updates