查询
select * from pmt_bolok
where id in (select max(id) from pmt_bolok
group by bolok_row)
MariaDB(10.0.17)中的此查询在0.094秒内执行得非常好。 (+ 0.047秒网络)
但是在mysql(5.5.32)中,在00:05:44秒非常慢。 (+ 478秒网络)
我的表是innodb,id
字段是主键。
[client]
port = 3306
socket = "C:/xampp/mysql/mysql.sock"
[mysqld]
autocommit=1
port= 3306
socket = "C:/xampp/mysql/mysql.sock"
basedir = "C:/xampp/mysql"
tmpdir = "C:/xampp/tmp"
datadir = "C:/xampp/mysql/data"
pid_file = "mysql.pid"
# enable-named-pipe
key_buffer = 16M
max_allowed_packet = 1M
sort_buffer_size = 512K
net_buffer_length = 8K
read_buffer_size = 256K
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 8M
log_error = "mysql_error.log"
plugin_dir = "C:/xampp/mysql/lib/plugin/"
server-id = 1
innodb_data_home_dir = "C:/xampp/mysql/data"
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = "C:/xampp/mysql/data"
innodb_buffer_pool_size = 16M
innodb_additional_mem_pool_size = 2M
innodb_log_file_size = 5M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
[mysqldump]
quick
max_allowed_packet = 16M
[mysql]
no-auto-rehash
[isamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[myisamchk]
key_buffer = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout
问题:
为什么在mysql中加速此查询的速度非常慢?
如何在mysql中增加此查询的速度?
除了my.ini,mysql和mariadb有什么不同?
答案 0 :(得分:0)
考虑转移到MySQL 5.7或将查询重写为
select * from pmt_bolok order by id desc limit 1
至于它为什么会发生 - MySQL 5.5没有子查询结果实现,WHERE子句中的子查询将对表中的每一行执行。
答案 1 :(得分:0)
IN ( SELECT ... )
在5.5及之前优化非常。
您有Groupwise max类型的查询。请参阅该链接以获得更好的性能。
至于您的设置,“您无法调整出现性能问题”。但是,假设您使用的是InnoDB,则应将innodb_buffer_pool_size
设置为可用 RAM的70%左右。这将有助于所有查询。如果你正在使用MyISAM,那么你不应该这样做。