gpt4 book ai didi

php - 避免从慢速查询日志中进行 RAND() 查询

转载 作者:行者123 更新时间:2023-11-29 03:04:52 24 4
gpt4 key购买 nike

--log-queries-not-using-indexes 打开时,如何避免记录此查询?

( source of the query )

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;

解释

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

最佳答案

我不知道有任何可能禁用单个查询的日志记录。 log_queries_not_using_indexes 是全局的,即时更改它会阻止记录任何并发查询(尽管我知道如果查询那么快,这是不太可能的)。

由于您实际上想降低此日志记录引起的负载,您可能想使用 log_throttle_queries_not_using_indexes (仅在 v5.6.5 中添加)或 min_examined_row_limit服务器选项。

后者存在于 session 级别。它可以在您的查询之前增加到一个荒谬的大值,而不会影响并发连接。令人惊讶的是,不需要特殊权限。

关于php - 避免从慢速查询日志中进行 RAND() 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17345369/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com