2
如何避免在打開--log-queries-not-using-indexes
時記錄此查詢?避免緩慢查詢日誌中的RAND()查詢
EXPLAIN SELECT id,autor,description
FROM (
SELECT @cnt := COUNT(*) + 1,
@lim := 3
FROM testimonale
) vars
STRAIGHT_JOIN
(
SELECT r.*,
@lim := @lim - 1
FROM testimonale r
WHERE (@cnt := @cnt - 1)
AND RAND() < @lim/@cnt
) i;
EXPLAIN
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY <derived2> system 1
1 PRIMARY <derived3> ALL 3
3 DERIVED r ALL 8 Using where
2 DERIVED Select tables optimized away
SET sql_log_bin = 0;查詢SET sql_log_bin = 1; ? – Dave
也可以做SET log_queries_not_using_indexes = 0;然後將它設置爲1,而不是你可能不得不查找實際的SQL變量名稱,但它的東西像上面。 – Dave
你問如何使這個查詢使用索引? – RandomSeed