【问题标题】:How do you create an index across different tables如何跨不同表创建索引
【发布时间】:2010-09-21 11:54:41
【问题描述】:
    Table A consists of (id, fieldA, fieldB, fieldC, fieldD)
    Table B consists of (id, tableA-id, fieldE, fieldF, fieldG)

My queries looks like this:-

1. select * from tableB b, tableA a where a.fieldA=? and a.fieldB=? and a.fieldC=? and a.fieldD=? and (b.fieldF >= '09/01/10' and b.fieldF <= '09/30/10');

2. select * from tableB b, tableA a where a.fieldA=? and a.fieldB=? and a.fieldC=? and a.fieldD=? and b.fieldE=? and (b.fieldF >= '09/01/10' and b.fieldF <= '09/30/10');

注意:fieldE是[2]的额外参数

我应该如何定义索引以适应这些查询

【问题讨论】:

  • 查询似乎缺少 tableA 和 tableB 之间的连接。
  • +1 @Pascal - 当然,除非 OP 想要笛卡尔连接。
  • 我在这里寻找笛卡尔加入

标签: mysql database indexing


【解决方案1】:

我认为,一个好的开始应该是:

create index huge_index on tableA (fieldA, fieldB, fieldC, fieldD)
create index modest_index on tableB (fieldF, fieldE);

也可能是 B.tableA-id。大师可能会建议 B 上的某种索引(包括 tableA-id 和其他值)是否有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-23
    • 1970-01-01
    相关资源
    最近更新 更多