我对查询有疑问。查询是否在订单中执行?例如,下面的查询:
SELECT colName1 from table where colName1 = 'a' and colName2 = 'b' limit 1
是否选择colName1 ='a'的所有行,然后从colName1 ='a'的所有行中选择colName2 ='b'的所有行?或者它是否一次完成所有操作?如果第一个为真,那么根据“a”和“b”的行数以及它们的写入顺序,查询可能需要更短或更长的时间来执行。
例如,如果在表中有1,000,000行,其中colName1 ='a',1行其中colName2 ='b',则:
1. First it would search the table for where colName1 = 'a'.
2. It would return 1,000,000 results.
3. Then in those 1,000,000 results, it would search for colName2 = 'b'.
4. Then it would return 1 result.
如果首先搜索colName2,那么它会更快:
1. First it would search the table for where colName2 = 'b'.
2. It would return 1 result.
3. Then in that 1 result, it would search for colName1 = 'a'.
4. Then it would return 1 result.
^ ---当然,如果colName1和colName2不同时执行,那只会是真的。那么,这是什么?查询是否按上述步骤执行?