Subject Re: [firebird-support] have one primary key only => better to have index or not?
Author Thomas Steinmaurer
> CREATE TABLE TEST(ITEM VARCHAR(20) NOT NULL PRIMARY KEY, VAL BLOB SUB_TYPE BINARY);
>
> SELECT VAL FROM TEST WHERE ITEM = '...';
>
> INSERT INTO TEST(ITEM, VAL) VALUES('...', ...);
>
> SELECT FIRST 1 RIGHT(ITEM, 8) FROM TEST WHERE LEFT(ITEM, 8) = '...' ORDER BY ITEM DESC;
>
> These are sql statements that I will use.
>
> Is it better to create indexes for this table?
> Someone told me that PRIMARY KEY field is automatically indexed internally. But I am not sure if it is true or not. Can anyone verify this?

True. You get an ascending index. While your first SELECT can use the
primary key index, your second with the substring WHERE clause won't.
You have to create an expression index for that. How many records do you
have in the table?


--
With regards,
Thomas Steinmaurer (^TS^)
Firebird Technology Evangelist

http://www.upscene.com/
http://www.firebirdsql.org/en/firebird-foundation/