confused: I have a InnoDB table look like this with (5,000,000 rows)
+------------------------+------------------+------+-----+---------------------+----------------+| Field | Type | Null | Key | Default | Extra |+------------------------+------------------+------+-----+---------------------+----------------+| item_id | int(10) unsigned | NO | PRI | NULL | auto_increment | | service_id | int(10) unsigned | NO | | NULL | | | publish_date | timestamp | NO | MUL | 0000-00-00 00:00:00 | | | guid | binary(16) | NO | MUL | NULL | | | user_id | int(10) unsigned | NO | MUL | NULL | | | service_type_id | int(10) unsigned | NO | | NULL | | | item_content_id | int(10) unsigned | NO | MUL | NULL | | | parent_item_content_id | int(10) unsigned | NO | MUL | 0 | | | source | char(31) | YES | | NULL | | | source_guid | binary(16) | NO | | NULL | | | service_item_guid | binary(16) | NO | | NULL | | +------------------------+------------------+------+-----+---------------------+----------------+
I'm trying to execute this query
SELECT item_id,item_content_id,service_id,user_id,service _type_id,H EX(guid) AS guid,publish_date,source FROM tblitems WHERE parent_item_content_id=0 AND service_type_id=101 AND user_id in (174131135,180679365,192202991,214776398,234247197 ,314202862 ,366489655,447894579,526731760,556098048,556652039 ,561040515 ,638419537,651980840,668107789,701655633,706950612 ,782231381 ,801508556,861750775,883262712,910940633,938219324 ,996426916 ,1053063122,1086695272,1115537464,1184584418,12338 32318,1238 904508,1249089491,1282863051,1312494447,1376282521 ,138160486 1,1385005897,1398891934,1402842598,1468859471,1529 349460,154 3114389,1548353079,1549054617,1571914454,165907087 1,16792789 87,1710759448,1730623872,1828437160,1832984639,185 4336685,19 05636426,1954649947,1968225540,2104630051,21206404 91,2135502 244,2137025828,2237617232,2239168055,2261941941,23 20472868,2 419062188,2450748621,2451715591,2513198664,2561373 602,261542 5018,2619967012,2625382898,2665924945,2681411117,2 730829516, 2758953497,2808142619,2880570142,2886001685,289836 0362,29007 59488,2925588951,2987536684,2999878127,3001889291, 3019677265 ,3031201704,3135304259,3181534725,3265244011,32728 00226,3286 774688,3290666357,3299691500,3327119216,3348536029 ,341292498 6,3416765413,3436263261,3490927984,3557766570,3561 494533,356 2545987,3606791845,3614305201,3739342454,386861759 7,38769940 02,3894695880,3904528983,3936052192,3947685092,395 5749448,39 61975961,3976397517,4025756315,4117134136,41253087 31,4255684 738) ORDER BY publish_date DESC, item_id DESC LIMIT 0,20;
I've tried the following indexes:
- (parent_item_content_id,publish_date)
- (user_id)
The query runs in 200ms.
Is there a ways to speed up the query?
THANKS IN ADVANCE
+------------------------+------------------+------+-----+---------------------+----------------+| Field | Type | Null | Key | Default | Extra |+------------------------+------------------+------+-----+---------------------+----------------+| item_id | int(10) unsigned | NO | PRI | NULL | auto_increment | | service_id | int(10) unsigned | NO | | NULL | | | publish_date | timestamp | NO | MUL | 0000-00-00 00:00:00 | | | guid | binary(16) | NO | MUL | NULL | | | user_id | int(10) unsigned | NO | MUL | NULL | | | service_type_id | int(10) unsigned | NO | | NULL | | | item_content_id | int(10) unsigned | NO | MUL | NULL | | | parent_item_content_id | int(10) unsigned | NO | MUL | 0 | | | source | char(31) | YES | | NULL | | | source_guid | binary(16) | NO | | NULL | | | service_item_guid | binary(16) | NO | | NULL | | +------------------------+------------------+------+-----+---------------------+----------------+
I'm trying to execute this query
SELECT item_id,item_content_id,service_id,user_id,service _type_id,H EX(guid) AS guid,publish_date,source FROM tblitems WHERE parent_item_content_id=0 AND service_type_id=101 AND user_id in (174131135,180679365,192202991,214776398,234247197 ,314202862 ,366489655,447894579,526731760,556098048,556652039 ,561040515 ,638419537,651980840,668107789,701655633,706950612 ,782231381 ,801508556,861750775,883262712,910940633,938219324 ,996426916 ,1053063122,1086695272,1115537464,1184584418,12338 32318,1238 904508,1249089491,1282863051,1312494447,1376282521 ,138160486 1,1385005897,1398891934,1402842598,1468859471,1529 349460,154 3114389,1548353079,1549054617,1571914454,165907087 1,16792789 87,1710759448,1730623872,1828437160,1832984639,185 4336685,19 05636426,1954649947,1968225540,2104630051,21206404 91,2135502 244,2137025828,2237617232,2239168055,2261941941,23 20472868,2 419062188,2450748621,2451715591,2513198664,2561373 602,261542 5018,2619967012,2625382898,2665924945,2681411117,2 730829516, 2758953497,2808142619,2880570142,2886001685,289836 0362,29007 59488,2925588951,2987536684,2999878127,3001889291, 3019677265 ,3031201704,3135304259,3181534725,3265244011,32728 00226,3286 774688,3290666357,3299691500,3327119216,3348536029 ,341292498 6,3416765413,3436263261,3490927984,3557766570,3561 494533,356 2545987,3606791845,3614305201,3739342454,386861759 7,38769940 02,3894695880,3904528983,3936052192,3947685092,395 5749448,39 61975961,3976397517,4025756315,4117134136,41253087 31,4255684 738) ORDER BY publish_date DESC, item_id DESC LIMIT 0,20;
I've tried the following indexes:
- (parent_item_content_id,publish_date)
- (user_id)
The query runs in 200ms.
Is there a ways to speed up the query?
THANKS IN ADVANCE
Comment