Re: Dual index question
From: Gus Teschke <gus.teschke_at_med.umich.edu>
Date: 5 Apr 1994 18:39:40 GMT
Message-ID: <gus.teschke-050494134525_at_no-name-medadmin.med.umich.edu>
>
> Can anyone answer the following question regarding
> dual indices on a table?
>
> Given a table FOO:
>
> Column Type
> foobar primary key
> foobee foriegn key
> foobat data
> fooboo data
>
> I want to create a unique index on column foobar to
> insure data integrity, but I also want a concatenated
> index on foobar & foobee in order to speed table joins.
> In many cases, I will not return any other data from FOO.
>
> If I do a select joining this table with the one
> where foobee is a primary key, and refer to both
> foobar and foobee in the where clause, which index
> will I be using?
>
> Thanks.
> -Woody
Received on Tue Apr 05 1994 - 20:39:40 CEST
Date: 5 Apr 1994 18:39:40 GMT
Message-ID: <gus.teschke-050494134525_at_no-name-medadmin.med.umich.edu>
Good luck,
Gus
SQL> create table taba (
2 foobee number constraint pk_foobee primary key, 3 d date 4 ); SQL> create table foo ( 2 foobar number constraint pk_foobar primary key using index, 3 foobee number constraint fk_foobee references taba (foobee), 4 foobat number, 5 fooboo number 6 );
SQL> create index ffcat_i on foo (foobar, foobee);
SQL> explain plan
2 set statement_id = 'ind1'
3 for
4 select f.foobar, f.foobee 5 from foo f, taba t 6 where f.foobee = t.foobee 7 and f.foobar = 123 8 and f.foobee = 456;
SQL> _at_iplan ind1
SQL> SELECT
2 substr(LPAD(' ',2*LEVEL)||OPERATION,1,30) "operation", 3 substr(OPTIONS,1,15) "options", 4 substr(OBJECT_NAME,1,30) "object_name" 5 FROM 6 PLAN_TABLE 7 WHERE 8 STATEMENT_ID='&&1' 9 CONNECT BY 10 PRIOR ID = PARENT_ID 11 and STATEMENT_ID = '&&1' 12 START WITH 13 ID = 1 14 and STATEMENT_ID = '&&1' 15 ORDER BY 16 ID; operation options object_name ------------------------------ --------------- ------------------------------ NESTED LOOPS TABLE ACCESS BY ROWID FOO INDEX UNIQUE SCAN PK_FOOBAR INDEX UNIQUE SCAN PK_FOOBEE
SQL> drop index ffcat_i;
SQL> create unique index ffcat_i on foo (foobar, foobee);
SQL> explain plan
2 set statement_id = 'ind3'
3 for
4 select f.foobar, f.foobee 5 from foo f, taba t 6 where f.foobee = t.foobee 7 and f.foobar = 123 8 and f.foobee = 456; operation options object_name ------------------------------ --------------- ------------------------------ NESTED LOOPS INDEX UNIQUE SCAN FFCAT_I INDEX UNIQUE SCAN PK_FOOBEE ______________________________________________In article <2nkbabINNin1_at_srvr1.engin.umich.edu>, lwk_at_engin.umich.edu (Lewis W Kellum) wrote:
>
> Can anyone answer the following question regarding
> dual indices on a table?
>
> Given a table FOO:
>
> Column Type
> foobar primary key
> foobee foriegn key
> foobat data
> fooboo data
>
> I want to create a unique index on column foobar to
> insure data integrity, but I also want a concatenated
> index on foobar & foobee in order to speed table joins.
> In many cases, I will not return any other data from FOO.
>
> If I do a select joining this table with the one
> where foobee is a primary key, and refer to both
> foobar and foobee in the where clause, which index
> will I be using?
>
> Thanks.
> -Woody
Received on Tue Apr 05 1994 - 20:39:40 CEST