How to create an index to filter a specific range? AFAIK it's impossible to create directly but I think it's possible simulate this feature.
Example: I wanna create an index for NAME column just to lines with STATUS = 'ACTIVE'
|
How to create an index to filter a specific range? AFAIK it's impossible to create directly but I think it's possible simulate this feature. Example: I wanna create an index for NAME column just to lines with STATUS = 'ACTIVE' |
|||||||
|
|
If I understand the question correctly, I think what would accomplish what you're trying to do is to create an index on both columns, NAME and STATUS. That would efficiently allow you to query where NAME='SMITH' and STATUS='ACTIVE' |
|||||||||||
|
|
You could do this by splitting the data between two tables, using views to union the two tables when all the data is needed, and indexing only one of the tables on that column - but I think this would cause performance problems for queries that need to run over the whole table unless the query planner is more clever than I give it credit for. Essentially you would be manually partitioning the table (and appying the index to only one of the partitions). Unfortunately the built-in table partitioning feature will not help you in your quest as you can not apply an index to a single partition. You could maintain an extra column with an index and only have a value in that column when the condition you want the index to be based upon is true, but this is likely to be labour intensive and of limited (or negative) value in terms of query efficiency and space saving. |
|||||||
|
|
You cannot do conditional indexing, but for your example, you can add a multi-column index on ( Even though it will index all the data in those columns, it will still help you find the names you are looking for with the status "active". |
|||
|
|