thanks can you help me please, I'm migrating an application and go to mysql 5.5 is very slow query returned thank you very much for your help.
SELECT DISTINCT b.cc46_cc55_field_id_id AS row_id, t0.cc46_value AS f_264, t1.cc46_value AS f_265, t2.cc46_value AS f_266
FROM tc46_fields_values b
LEFT OUTER JOIN tc46_fields_values t0 ON b.cc46_cc55_field_id_id = t0.cc46_cc55_field_id_id
AND t0.cc46_cc26_field_id = 264
LEFT OUTER JOIN tc46_fields_values t1 ON b.cc46_cc55_field_id_id = t1.cc46_cc55_field_id_id
AND t1.cc46_cc26_field_id = 265
LEFT OUTER JOIN tc46_fields_values t2 ON b.cc46_cc55_field_id_id = t2.cc46_cc55_field_id_id
AND t2.cc46_cc26_field_id = 266
WHERE b.cc46_cc55_field_id_id IN (5924,5925,5926,5927,5928,5929,5930,5931,5932,5933,5934,5935,5936,5937,5938,5939,5940,5941,5942,5943,5944,5945,5946,5947,5948,5949,5950,5951,5952,5953,5954,5955,5956,5957,5958,5959,5960,5961,5962,5963,5964,5965,5966,5967,5968,5969,5970,5971,5972,5973,5974,5975,5976,5977,5978,5979,5980,5981,5982,5983,5984,5985,5986,5987,5988,5989,5990,5991,5992,5993,5994,5995,5996,5997,5998,5999,6000,6001,6002,6003,6004,6005,6006,6007,6008,6009,6010,6011,6012,6013,6014,6015,6016,6017,6018,6019,6020,6021,6022,6023,6024,6025,6026,6027,6028,6029,6030,6031,6032,6开发者_开发百科033,6034,6035,6036,6037,6038,6039,6040,6041,6042,6043,6044,6045,6046,6047,6048,6049,6050,6051,6052,6053,6054,6055,6056,6057,6058,6059,6060,6061,6062,6063,6064,6065,6066,6067,6068,6069,6070,6071,6072,6073,6074,6075,6076,6077,6078,6079,6080,6081,6082,6083,6084,6085,6086,6087,6088,6089,6090,6091,6092,6093,6094,6095,6096,6097,6098,6099,6100,6101,6102,6103,6104,6105,6106,6107,6108,6109,6110,6111,6112,6113,6114,6115,6116,6117,6118,6119,6120,6121,6122,6123,6124,6125,6126,6127,6128,6129,6130,6131,6132,6133,6134,6135,6136,6137,6138,6139,6140,6141,6142,6143,6144,6145,6146,6147,6148,6149,6150,6151,6152,6153,6154,6155,6156,6157,6158,6159,6160,6161,6162,6163,6164,6165,6166)
Ensure you have an index on the field "cc46_cc55_field_id_id". In addition, don't use your list of almost 200 IDs... Since your version is all sequential, just use a BETWEEN clause..
SELECT DISTINCT
b.cc46_cc55_field_id_id AS row_id,
t0.cc46_value AS f_264,
t1.cc46_value AS f_265,
t2.cc46_value AS f_266
FROM
tc46_fields_values b
LEFT JOIN tc46_fields_values t0
ON b.cc46_cc55_field_id_id = t0.cc46_cc55_field_id_id
AND t0.cc46_cc26_field_id = 264
LEFT JOIN tc46_fields_values t1
ON b.cc46_cc55_field_id_id = t1.cc46_cc55_field_id_id
AND t1.cc46_cc26_field_id = 265
LEFT OUTER JOIN tc46_fields_values t2
ON b.cc46_cc55_field_id_id = t2.cc46_cc55_field_id_id
AND t2.cc46_cc26_field_id = 266
WHERE
b.cc46_cc55_field_id_id between 5924 and 6166
To see what indexes are used run
EXPLAIN SELECT DISTINCT
b.cc46_cc55_field_id_id AS row_id,
t0.cc46_value AS f_264,
t1.cc46_value AS f_265,
t2.cc46_value AS f_266
FROM
tc46_fields_values b
LEFT JOIN tc46_fields_values t0
ON b.cc46_cc55_field_id_id = t0.cc46_cc55_field_id_id
AND t0.cc46_cc26_field_id = 264
LEFT JOIN tc46_fields_values t1
ON b.cc46_cc55_field_id_id = t1.cc46_cc55_field_id_id
AND t1.cc46_cc26_field_id = 265
LEFT OUTER JOIN tc46_fields_values t2
ON b.cc46_cc55_field_id_id = t2.cc46_cc55_field_id_id
AND t2.cc46_cc26_field_id = 266
WHERE
b.cc46_cc55_field_id_id between 5924 and 6166
Try to this query instead:
SELECT b.cc46_cc55_field_id_id AS row_id, t0.cc46_value AS f_264, t1.cc46_value AS f_265, t2.cc46_value AS f_266
FROM
tc46_fields_values b LEFT OUTER JOIN tc46_fields_values t0 ON b.cc46_cc55_field_id_id = t0.cc46_cc55_field_id_id
LEFT OUTER JOIN tc46_fields_values t1 ON b.cc46_cc55_field_id_id = t1.cc46_cc55_field_id_id
LEFT OUTER JOIN tc46_fields_values t2 ON b.cc46_cc55_field_id_id = t2.cc46_cc55_field_id_id
WHERE
t0.cc46_cc26_field_id = 264
AND
t1.cc46_cc26_field_id = 265
AND
t2.cc46_cc26_field_id = 266
AND
b.cc46_cc55_field_id_id IN (5924,5925,5926,5927,5928,5929,5930,5931,5932,5933,5934,5935,5936,5937,5938,5939,5940,5941,5942,5943,5944,5945,5946,5947,5948,5949,5950,5951,5952,5953,5954,5955,5956,5957,5958,5959,5960,5961,5962,5963,5964,5965,5966,5967,5968,5969,5970,5971,5972,5973,5974,5975,5976,5977,5978,5979,5980,5981,5982,5983,5984,5985,5986,5987,5988,5989,5990,5991,5992,5993,5994,5995,5996,5997,5998,5999,6000,6001,6002,6003,6004,6005,6006,6007,6008,6009,6010,6011,6012,6013,6014,6015,6016,6017,6018,6019,6020,6021,6022,6023,6024,6025,6026,6027,6028,6029,6030,6031,6032,6033,6034,6035,6036,6037,6038,6039,6040,6041,6042,6043,6044,6045,6046,6047,6048,6049,6050,6051,6052,6053,6054,6055,6056,6057,6058,6059,6060,6061,6062,6063,6064,6065,6066,6067,6068,6069,6070,6071,6072,6073,6074,6075,6076,6077,6078,6079,6080,6081,6082,6083,6084,6085,6086,6087,6088,6089,6090,6091,6092,6093,6094,6095,6096,6097,6098,6099,6100,6101,6102,6103,6104,6105,6106,6107,6108,6109,6110,6111,6112,6113,6114,6115,6116,6117,6118,6119,6120,6121,6122,6123,6124,6125,6126,6127,6128,6129,6130,6131,6132,6133,6134,6135,6136,6137,6138,6139,6140,6141,6142,6143,6144,6145,6146,6147,6148,6149,6150,6151,6152,6153,6154,6155,6156,6157,6158,6159,6160,6161,6162,6163,6164,6165,6166)
GROUP BY
b.cc46_cc55_field_id_id
instead of using distinct use group by.
精彩评论