Subject | Re: 2 Very simple index questions |
---|---|
Author | Adam |
Post date | 2007-01-25T06:03:20Z |
--- In firebird-support@yahoogroups.com, Vlad Orlovsky
<vlad.orlovsky@...> wrote:
No. An ascending index is automatically created on any constraint,
including primary keys, unique constraints and foreign keys so this is
not necessary (unless you require a descending index on the foreign
key field for some other reason).
care which way you write it. Although the index is available on both
fields, it will prefer the primary key. Firebird is also able to
combine both indices if required, but probably wont bother in this case.
Adam
<vlad.orlovsky@...> wrote:
>is a foreign key?
> Hi All,
>
> I have 2 very basic questions about indexes.
>
> 1) Do I need to create a separate index for a column in a table that
No. An ascending index is automatically created on any constraint,
including primary keys, unique constraints and foreign keys so this is
not necessary (unless you require a descending index on the foreign
key field for some other reason).
>They are both the same speed. The optimiser is smart enough to not
> Ex:
> ROLES table
> ROLE_ID INTEGER -- PK
> ROLE_NAME VARCHAR(50)
>
> USERS table
> USER_ID INTEGER -- PK
> ROLE_ID INTEGER -- FK ?????
> USER_NAME VARCHAR(50)
> ....
>
> 2) Which SELECT is faster(using above tables):
>
> SELECT * FROM USERS WHERE USER_ID = 1 AND ROLE_ID =10
> -- OR
> SELECT * FROM USERS WHERE ROLE_ID =10 AND USER_ID = 1
>
care which way you write it. Although the index is available on both
fields, it will prefer the primary key. Firebird is also able to
combine both indices if required, but probably wont bother in this case.
Adam