Subject Re: [firebird-support] does FB support clustered indices?
Author Ann W. Harrison
judlian23 wrote:
> Hi everyone,
>
> I saw on a post from 2006 that FB does not support clustered indices.

That's right. Firebird uses only b*tree indexes. All data is stored
on data pages, in (approximately) the same order that the records were
inserted.

> I am currently using Firebird-2.1.1.17910-0_Win32_embed. Does this
> version support clustered indices? I did not see it in the SQL:2003
> standard, but then again, that nuances of that version of SQL is a
> little foreign to me.

Indexes aren't part of the standard. By policy the SQL standard
addresses the semantics of access to data, but not the storage
method or other mechanisms to reduce access time.
>
> What I mean by clustered is that I need records placed in my DB in
> order. I want them sorted by time, and these records will be inserted
> by time, so hopefully inserts would be fast with a clustered index
> because the db just needs to append the record.

Unless you delete or update records, newly inserted records will be
added to the last data page in the table. As long as you insert
records in the order that you want them stored, and don't delete
or modify them, you'll get the effect your looking for.

When you delete a record, the space it used will eventually be
reclaimed and made available for reused. When you update a
record, Firebird stores both the old and new versions of the
record - the old one is ordinarily stored as a difference, so
it's small - and when the updates are committed, eventually
the space used for the old version also becomes available,
and will eventually be reused.

So occasionally, Firebird might store a record in space that's
been released rather than at the end of the table. Under the
same circumstances, a clustered index would develop holes -
partially empty pages where the space could not be reused -
that would reduce retrieval performance.

Clustered indexes wouldn't make inserts faster than they are now.
If records are inserted in random order relative to their clustering
key but retrieved in ranges on that key, then a clustered index
could reduce the retrieval time. But that's not what you're
doing.

Good luck,

Ann