sql语句1
select a.url,a.title,a.thumb,b.introduction,a.userid ,a.areaid,b.price FROM 
phpcms_content a,phpcms_c_product b,phpcms_member c
where a.status=99 and a.contentid=b.contentid  AND a.thumb!='' and
a.catid in (1249,1082,1084,1083,1250,1087,1088,1089,1090,1091,1996,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,1154,1155,1156,1157,1158,1159,1160,1161,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,1183,1184,1185,1187,1188,1189,1190,1191,1192,1193,1194,1195,1196,1197,1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,1261,1262,1263,1264,1265,1997,1998,2017,2018,2019,2020,2021) 
and  1 AND  a.title like '%%' and a.userid=c.userid  ORDER BY c.groupid desc,a.inputtime desc 
=========================================================================================================
SQL语句2
SELECT a.contentid,a.userid,a.title,a.thumb,a.description,a.url,a.style,a.catid,a.areaid,a.inputtime,b.stars,
b.price,b.brand,b.other FROM 
phpcms_content a,phpcms_c_product b,phpcms_member c 
where a.status=99 and a.contentid=b.contentid and a.thumb!='' and
a.catid in (1249,1082,1084,1083,1250,1087,1088,1089,1090,1091,1996,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1117,1118,1119,1120,1121,1122,1123,1124,1125,1126,1127,1128,1129,1130,1131,1132,1133,1134,1135,1136,1137,1138,1139,1140,1141,1142,1143,1144,1145,1146,1147,1148,1149,1150,1151,1152,1153,1154,1155,1156,1157,1158,1159,1160,1161,1162,1163,1164,1165,1166,1167,1168,1169,1170,1171,1172,1173,1174,1175,1176,1177,1178,1179,1180,1181,1182,1183,1184,1185,1187,1188,1189,1190,1191,1192,1193,1194,1195,1196,1197,1251,1252,1253,1254,1255,1256,1257,1258,1259,1260,1261,1262,1263,1264,1265,1997,1998,2017,2018,2019,2020,2021) 
and 1 and a.title like '%%' and a.userid=c.userid ORDER BY c.groupid desc,a.inputtime desc 
sql语句1 和 sql语句2 查询条件一样, 为什么查的字段不一样 速度不一样,求解?
sql语句1 用了15秒
sql语句2 却只用4秒

解决方案 »

  1.   

    语句1与语句2查询相异的字段是:
    b.introduction
     
    语句2与语句1查询相异的字段是:a.contentid,a.description,a.style,a.catid,a.inputtime,b.stars,b.brand,b.other 初步判断是b.introduction字段影响了语句1的速度,楼主将这个字段也加到语句2中试一试看看所用时间
      

  2.   

    试过很多次了,  都这样。 而且查一次数据后, 不可在查第二次。 MYSQL似乎自己有缓冲机制, 第二次不到一秒就查出来了