简体   繁体   English

索引表以提高查询性能

[英]Indexing a table for better performance by a query

What index/indexes would you recommend to be created on the table for making the following type of query more efficient: 建议您在表上创建哪些索引,以提高以下类型的查询的效率:

SELECT MAX(val1)
FROM table
WHERE val2 = 'x' OR val3 = 'y'

x and y are of course variable. x和y当然是可变的。 val2 and val3 are almost always unique, some duplicates may occur. val2和val3几乎总是唯一的,可能会出现一些重复。

have an index on val2 + val1 and another on val3 + val1 and write query like: val2 + val1上有一个索引,在val3 + val1上有另一个,并编写如下查询:

SELECT MAX(val1)
FROM (SELECT max(val1) FROM table where val2 = 'x'
      UNION ALL
      SELECT max(val1) FROM table val3 = 'y'
     ) dt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM