Discussions
Categories
- 196.7K All Categories
- 2.2K Data
- 235 Big Data Appliance
- 1.9K Data Science
- 449.8K Databases
- 221.5K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 549 MySQL Community Space
- 477 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3K ORDS, SODA & JSON in the Database
- 532 SQLcl
- 4K SQL Developer Data Modeler
- 186.8K SQL & PL/SQL
- 21.2K SQL Developer
- 295.3K Development
- 17 Developer Projects
- 138 Programming Languages
- 292K Development Tools
- 104 DevOps
- 3.1K QA/Testing
- 645.9K Java
- 27 Java Learning Subscription
- 37K Database Connectivity
- 153 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.1K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 17 Java Essentials
- 158 Java 8 Questions
- 85.9K Java Programming
- 79 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.2K Java SE
- 13.8K Java Security
- 203 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 390 LiveLabs
- 37 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.6K Other Languages
- 2.3K Chinese
- 170 Deutsche Oracle Community
- 1K Español
- 1.9K Japanese
- 230 Portuguese
create index A and A + B and A+B+C

This is index question.
If you have oracle database, and have the index A + B + C colume.
You might need the index A+ B or A.
Oracle Database automatically check these case and prevent these case,
So can save disk space and prevent not using original A+ B+ C index.
What is your opinion?
If This is the right scenario we might ask oracle to make constraint on index creation.
So we only have one index A+B+C. and probibit creating A+B or A by mistake.
Give your opinion.
Xie Xie
Answers
-
composite index and normal index are good at different times.
Search on composite index will be slower in compare to if it is done at simple index for that column.
Composite index may give you faster access if all columns of it are used in predicates in compare to simple index.
I would suggest you to test it yourself
-
As Nimish said, search on composite indexes is slower. Try yo make index(with minimal columns) only when it is really giving benefits. In case you are suggesting, index on 2 columns might be best as it solves 90% of scenarios.
Index should only be taken as performance tool .
Thanks,
Harman
-
I can't create database triggers to be fired at index creation, but given the create index statement I could check
with /* simulating user_ind_columns */
user_ind_cols(index_name,table_name,column_name,column_position,column_length,char_length,descend) as
(select 'index_name1','table_name','column_name_1',1,10,10,'ASC' from dual union all
select 'index_name1','table_name','column_name_2',2,10,10,'ASC' from dual union all
select 'index_name1','table_name','column_name_3',3,10,10,'ASC' from dual union all
select 'index_name2','table_name','column_name_1',1,10,10,'ASC' from dual union all
select 'index_name2','table_name','column_name_4',2,10,10,'ASC' from dual
),
create_index as
(select regexp_substr(create_index,' on (\w+) ',1,1,'i',1) table_name,
regexp_substr(create_index,'\((.+)\)',1,1,'i',1) index_columns
from (select 'create index index_name on table_name (column_name_1,column_name_2)' create_index
from dual
)
)
select table_name,
index_name,
column_list,
(select index_columns from create_index) to_be_created
from (select table_name,
index_name,
listagg(column_name,',') within group (order by column_position) column_list
from user_ind_cols
where table_name = (select table_name
from create_index
)
group by table_name,index_name
)
where instr(column_list,(select index_columns from create_index)) = 1
TABLE_NAME INDEX_NAME COLUMN_LIST TO_BE_CREATED table_name index_name1 column_name_1,column_name_2,column_name_3 column_name_1,column_name_2 Regards
Etbin
-
Suppose we have a scenario where most of SQL Statements uses all three A,B,C in their WHERE condition and few queries use only one of above three columns in the WHERE clause. We have two options:
- create 4 indexes
- index for A only
- index for B only
- index for C only
- composite index on A,B.C
- Create single composite index on A,B,c
If we use first option, the select queries shall be very fast whether they use single column (A,B,C) in the where clause or all three columns. We'll be getting best performance assuming that optimizer is using these indexes. But the insert/update/delete statements shall be slow because for every DML operation, Oracle 'll have to update all 4 indexes.In case of second option, most of queries using all three columns in where clause shall be fast. However those queries shall be comparatively slow which are using only one of the above three columns due to index range/skip scans. In this case, DML statements shall be fast as now only one index need to be maintained in case of such operation.
By not restricting us on index creation, Oracle has given us option to decide the number and order of indexes. Different applications have different requirements. Some want SELECT queries fast to display results immediately to the client while some wants fast DML operations.
- create 4 indexes