如何更快地使MySQL查询

时间:2016-03-16 14:50:15

标签: mysql

下面我可能是我写过的最大的单个MySQL查询。正如预期的那样,当我运行MySQL服务器时,它似乎会花费相当大的代价。或者更糟糕的是,它会同时运行多个。

我在查询中所做的一切都是出于我认为必须使用已经存在的表结构得到的结果。

所以我的问题是:
您是否可以看到我可以对此查询进行任何明显的更改以提高性能? 我采取的任何步骤都不需要? 任何DB更改/ tweek,索引等。我能做些什么来使服务器上的负载更容易?

我向批评的互联网开放,请善待,或者至少是建设性的,我是新的。 :)

# id, select_type, table, type, possible_keys, key, key_len, ref, rows, Extra
1, PRIMARY, td, index, PRIMARY,Area, Area, 138, , 65286, Using index
1, PRIMARY, tq, eq_ref, PRIMARY, PRIMARY, 4, Job1111.td.ID, 1, 
1, PRIMARY, <derived2>, ref, <auto_key0>, <auto_key0>, 5, Job1111.td.ID, 1326, 
1, PRIMARY, <derived9>, ref, <auto_key0>, <auto_key0>, 4, Job1111.td.ID, 10, 
1, PRIMARY, <derived10>, ref, <auto_key0>, <auto_key0>, 4, Job1111.td.ID, 10, 
1, PRIMARY, <derived11>, ref, <auto_key0>, <auto_key0>, 4, Job1111.td.ID, 10, 
1, PRIMARY, <derived12>, ref, <auto_key0>, <auto_key0>, 4, Job1111.td.ID, 10, 
1, PRIMARY, <derived13>, ref, <auto_key0>, <auto_key0>, 4, Job1111.td.ID, 10, 
1, PRIMARY, <derived14>, ref, <auto_key0>, <auto_key0>, 4, Job1111.td.ID, 10, 
14, DERIVED, td, ALL, PRIMARY, , , , 65286, Using where
14, DERIVED, tq, eq_ref, PRIMARY, PRIMARY, 4, Job1111.td.ID, 1, 
13, DERIVED, td, ALL, PRIMARY, , , , 65286, Using where
13, DERIVED, tq, eq_ref, PRIMARY, PRIMARY, 4, Job1111.td.ID, 1, 
12, DERIVED, td, ALL, PRIMARY, , , , 65286, Using where
12, DERIVED, tq, eq_ref, PRIMARY, PRIMARY, 4, Job1111.td.ID, 1, 
11, DERIVED, td, ALL, PRIMARY, , , , 65286, Using where
11, DERIVED, tq, eq_ref, PRIMARY, PRIMARY, 4, Job1111.td.ID, 1, 
10, DERIVED, td, ALL, PRIMARY, , , , 65286, Using where
10, DERIVED, tq, eq_ref, PRIMARY, PRIMARY, 4, Job1111.td.ID, 1, 
9, DERIVED, td, ALL, PRIMARY, , , , 65286, Using where
9, DERIVED, tq, eq_ref, PRIMARY, PRIMARY, 4, Job1111.td.ID, 1, 
2, DERIVED, ss, ref, fk_StatusSubmissionId_idx,fk_tblSubmissionStatus_tblActivityStatuses_idx, fk_tblSubmissionStatus_tblActivityStatuses_idx, 5, const, 10, Using where; Using temporary; Using filesort
2, DERIVED, at, eq_ref, PRIMARY, PRIMARY, 4, Job1111.ss.ActivityType, 1, Using where
2, DERIVED, sd, eq_ref, PRIMARY, PRIMARY, 4, Job1111.ss.fk_SubmissionId, 1, Using index
2, DERIVED, se, ALL, PRIMARY, , , , 6, Using where; Using join buffer (Block Nested Loop)
2, DERIVED, <derived3>, ALL, , , , , 10, Using where; Using join buffer (Block Nested Loop)
2, DERIVED, <derived4>, ALL, , , , , 12, Using where; Using join buffer (Block Nested Loop)
2, DERIVED, <derived5>, ALL, , , , , 8, Using where; Using join buffer (Block Nested Loop)
2, DERIVED, <derived6>, ALL, , , , , 3, Using where; Using join buffer (Block Nested Loop)
2, DERIVED, <derived7>, ALL, , , , , 2, Using where; Using join buffer (Block Nested Loop)
2, DERIVED, <derived8>, ref, <auto_key0>, <auto_key0>, 4, Job1111.ss.fk_BidIDAssigned, 668, 
8, DERIVED, tq, ALL, , , , , 66824, 
7, DERIVED, sm, index, , fk_MiscSubmissionId_idx, 4, , 1, Using index
6, DERIVED, ssu, index, , SubmissionId_idx, 4, , 3, Using index
5, DERIVED, st, ALL, , , , , 8, 
4, DERIVED, sw, index, , fk_WeldSubmssionId_idx, 4, , 12, Using index
3, DERIVED, sb, index, , fk_BoltUpSubmissionId_idx, 4, , 10, Using index

更新 根据要求(以及一个很好的请求)这是EXPLAIN的输出

    int max=10;
    public int[] a = new int[max];

    @Override
    public void deleteValues(int value) {
    int tempIndex=0;

    for (int i = 0; i <50 ; i++) {
        if (a[tempIndex] == value) {
            a[tempIndex] = a[tempIndex + 1];
            a[tempIndex + 1] = 0;
        } else if (a[tempIndex] == 0) {
            a[tempIndex] = a[tempIndex + 1];
            a[tempIndex + 1] = 0;

        } else {
            tempIndex++;

        }

    }


}

0 个答案:

没有答案