[英]Oracle 12c - which index should be used for a table with partitions and sub-partitions
I have a table of 500M records in Oracle 12c. 我在Oracle 12c中有一张500M记录的表。 Table is partitioned per 1 varchar column and sub-partitioned per other varchar column. 表按1个varchar列进行分区,并按其他varchar列进行子分区。
What indexes should be used with queries that use these 2 columns in Where clause? 在Where子句中使用这两列的查询应使用哪些索引?
I am assuming local partitioned indexes are the best choice but wanted to get more insight on when is this a case and how is the best to create them? 我假设本地分区索引是最佳选择,但想了解何时出现这种情况以及如何最好地创建它们?
Oracle is capable of partition pruning , meaning that if your query has the partition key column(s) in the where clause, Oracle is smart enough to only query those partitions that are relevant. Oracle能够进行分区修剪 ,这意味着,如果您的查询在where子句中具有分区键列,则Oracle足够聪明,只查询相关的那些分区。 In such case a local partitioned index is more beneficial because it is "local to the partition", ie the index is also partitioned the same way and Oracle will only read the relevant index entries for those partition that are relevant. 在这种情况下, 本地分区索引会更有利,因为它是“分区本地的”,即索引也以相同的方式分区,并且Oracle将只读取与该分区相关的相关索引条目。
If however you have a query that doesn't have the partition key column(s) in the where clause Oracle can't apply partition pruning and will have no other choice but to scan all local partitioned indexes or, worst case, the entire table for the data. 但是,如果查询的where子句中没有分区键列,那么Oracle将无法应用分区修剪,并且除了扫描所有本地分区索引 (最坏的情况是扫描整个表)之外别无选择用于数据。 This is where a global partitioned index will come in handy on those columns that are in the where clause. 在这里,全局分区索引将在where子句中的那些列上派上用场。 In that case Oracle creates an index over those columns across partitions and knows exactly which records to read from which partitions that qualify for the where clause of the statement. 在那种情况下,Oracle在分区中的这些列上创建索引,并确切知道要从哪些分区中读取哪些记录符合该语句的where子句。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.