Subject | Re: High selectivity |
---|---|
Author | Fabrice Aeschbacher |
Post date | 2003-09-26T15:20:05Z |
Hi Jonathan,
I would write following before trigger:
CREATE GENERATOR STATE_GEN;
CREATE TRIGGER MY_TABLE_BI FOR MY_TABLE
ACTIVE BEFORE INSERT, UPDATE
AS
BEGIN
IF ( NEW.STATE IS NULL ) THEN NEW.STATE = 0;
IF ( NEW.STATE = 1 ) THEN NEW.STATE = GEN_ID( STATE_GEN, 1 );
END !!
(if you are using FB 1.0, make two different triggers for insert /
update)
So the STATE column will allways have either a unique non-zero value,
or a zero value. As long as the number of records having STATE=0 is
not too big, you can create an inder on that column.
HTH,
Fabrice
> >Suppose for instance that I have a STATE field on a table, that hastwo
> >possible values, 0 and 1.up in
> >All new records start out in STATE 0, and after a while, they end
> >STATE 1. Obviously, the number of records in STATE 0 will remainroughly
> >constant, whereas the number of records in STATE 1 will becontinually
> >growing. If (as it is highly likely), I know in advance that I willfrequently
> >almost never need to select all records in STATE 1, but very
> >all records in STATE 0, would it not be advantageous to define anindex?
I would write following before trigger:
CREATE GENERATOR STATE_GEN;
CREATE TRIGGER MY_TABLE_BI FOR MY_TABLE
ACTIVE BEFORE INSERT, UPDATE
AS
BEGIN
IF ( NEW.STATE IS NULL ) THEN NEW.STATE = 0;
IF ( NEW.STATE = 1 ) THEN NEW.STATE = GEN_ID( STATE_GEN, 1 );
END !!
(if you are using FB 1.0, make two different triggers for insert /
update)
So the STATE column will allways have either a unique non-zero value,
or a zero value. As long as the number of records having STATE=0 is
not too big, you can create an inder on that column.
HTH,
Fabrice