MySQL查询速度很快,但是当我查询子查询时,它变得非常慢

时间:2017-11-23 13:21:37

标签: mysql

当我查询时:

select
   *
from
   userlogs_temp
where
   (
       last_analyze_time is NULL
           OR
       last_analyze_time < acctupdatetime
   )
   and
       came_from_other_servers = 0 and
       radacctid % 10 = 4

这是该查询的个人资料(总行数1583, 0.0009秒

first query profile

但是当我运行这个查询时:

select
   *
from
 (
    the above query
 ) sq

这是该查询的个人资料(总行数1583, 0.8052秒

second query profile

可能是什么问题?我认为问题是创建临时表,但磁盘i / o性能是正常的。我怎么能找到问题?当我在笔记本电脑上尝试相同的数据和相同的查询时,一切正常,第二次查询几乎与第一次查询相同。

这是my.cnf:

[mysqld]
bind-address = 127.0.0.1
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock


#innodb
innodb_lock_wait_timeout=120
innodb_buffer_pool_size=20G
innodb_additional_mem_pool_size=256M
innodb_file_per_table=1
innodb_log_buffer_size=256M
innodb_flush_log_at_trx_commit=2
innodb_flush_method=O_DIRECT

innodb_buffer_pool_instances = 6
innodb_read_io_threads = 16
innodb_write_io_threads = 16
innodb_thread_concurrency = 0
innodb-flush-log-at-trx-commit = 2


slow-query-log=1
long-query-time=1
skip-external-locking
skip-name-resolve
max_connections=250
key_buffer_size=8192M
max_allowed_packet=268435456
table_open_cache=100000
sort_buffer_size=2M
read_buffer_size=4096K
read_rnd_buffer_size=2048K
myisam_sort_buffer_size=2048M
query_cache_limit=5M
query_cache_size=4096M
query_cache_type=0
event_scheduler=ON
thread_cache_size=50
transaction-isolation=READ-COMMITTED
tmp_table_size=256M
max_heap_table_size=256M
open-files-limit=65535
table-definition-cache=4096
table-open-cache=10240

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Recommended in standard MySQL setup
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 






[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
connect_timeout=15
interactive_timeout=60

0 个答案:

没有答案
相关问题