sql - oracle query is not using indexes -
i brand new oracle , although have used sql server extensively have not had need delve details of database design ... indexes. have spent deal of time sitting through tutorials on indexes ... both in concept oracle specific.
in effort put understanding practice set simple table basic indexes.
create table "system"."tbl_person" ( "person_id" number(10,0) not null enable, "first_name" nvarchar2(120) not null enable, "middle_name" nvarchar2(120), "last_name" nvarchar2(120) not null enable, "dob" date not null enable, "is_male" nchar(1) default 't' not null enable, constraint "tbl_person_pk" primary key ("person_id") ) as can see person_id field contains unique rowid each record in table , auto-incrementing primary key.
(please don't hung on missing sql unless pertains issue of indexes not working. tried select relevant sql ddl , may have missed items. there ton of stuff there didn't think relevant issue tried trim out)
i have created couple of additional non-clustered indexes on table.
create index "system"."idx_last_name" on "system"."tbl_person" ("last_name") create index "system"."idx_person_name" on "system"."tbl_person" ("first_name", "last_name") when run "explain plan" on following sql notified pk index used expected.
select * tbl_person person_id = 21 
however when run query select particular last_name last_name index seems go ignored.
select * tbl_person last_name = 'stenstrom'
why not use idx_last_name? it's worth have same issue composite index idx_person_name.
the key question column "cardinality". have 5 rows estimated being returned table.
oracle has choice between 2 execution plans:
- load data page. scan 5 records on data page , choose one(s) match condition.
- load index , scan match. load data page , lookup matching record(s).
oracle has concluded 5 records, first approach faster. if load more data table, should see execution plan change. alternatively, if had select last_name instead of select *, oracle might choose index.
Comments
Post a Comment