We have a query that is called very frequently, so I would like to improve performance, but some colleagues are concerned about the index's size and its impact on inserts an updates.
SELECT field1, field2
FROM table1
WHERE field3 = '101'
AND field2 = @variable
Table table1
has about 5 million rows, but only about 2000 has field3 = 101
.
CREATE TABLE table1 (
field1 varchar
field2 int
field3 int);
Would it be possible to create and index for (field2, field1) only for these 2000 rows in oracle 11g?
How can I do it?
Best Answer
Database SQL Language Reference - CREATE INDEX
Demo
P.s.
The use of virtual column makes the querying more user friendly.
If the index would have been defined as -
then in order to use the index, the query should have looked like -