我們最近將percona 5.5 sql server升級到了percona 5.7。到目前爲止工作良好。不幸的是,我們有一個巨大的查詢,在5.7以下速度極慢。在5.5之下。即使使用sql_no_cache,也只需不到一秒鐘的時間。隨着Percona 5.7。執行此查詢最多需要1分鐘。奇怪的是,隨着我們使用更多的組合索引,它變得越慢。刪除所有組合的指示導致執行時間爲30秒。強制sql_straight_join使查詢在不到一秒的時間內運行。Percona 5.7在很多聯接上緩慢
所以這裏是查詢:
SELECT t0_.tree_id AS tree_id0, t1_.treetype_name AS treetype_name1, c2_.contentelement_id AS contentelement_id2, t0_.tree_name AS tree_name3, (CASE WHEN t3_.treetype_name <> 'global' THEN t4_.tree_name ELSE t0_.tree_name END) AS sclr4, p5_.picture_id AS picture_id5, t6_.tree_misc_value_text AS tree_misc_value_text6, (CASE WHEN t3_.treetype_name <> 'global' THEN t7_.tree_misc_value_text ELSE t6_.tree_misc_value_text END) AS sclr7, w8_.widgetgeneral_slug AS widgetgeneral_slug8, (CASE WHEN t3_.treetype_name <> 'global' THEN w9_.widgetgeneral_slug ELSE w8_.widgetgeneral_slug END) AS sclr9, t10_.tree_misc_value_text AS tree_misc_value_text10, t11_.tree_misc_value_text AS tree_misc_value_text11
FROM tree_relation t12_
INNER JOIN tree t4_ ON t12_.tree_relation_parent = t4_.tree_id
INNER JOIN treetype t3_ ON t4_.tree_type_id = t3_.treetype_id AND (t3_.treetype_name IN ('global', 'country'))
INNER JOIN contentelement c13_ ON t4_.tree_id = c13_.contentelement_tree_id
INNER JOIN contentleaf c14_ ON c13_.contentelement_contentleaf_id = c14_.contentleaf_id AND (c14_.contentleaf_contentbranch_id = 1)
INNER JOIN widgetgeneral w9_
INNER JOIN widgetabstract w15_ ON w9_.widgetabstract_id = w15_.widgetabstract_id AND (w15_.widgetabstract_contentelement_id = c13_.contentelement_id AND w15_.widgetabstract_discriminator IN ('general') AND w15_.widgetabstract_state = 'preview')
INNER JOIN tree t0_ ON t12_.tree_relation_child = t0_.tree_id
INNER JOIN treetype t1_ ON t0_.tree_type_id = t1_.treetype_id AND (t1_.treetype_name IN ('city','region'))
INNER JOIN contentelement c2_ ON t0_.tree_id = c2_.contentelement_tree_id
INNER JOIN contentleaf c16_ ON c2_.contentelement_contentleaf_id = c16_.contentleaf_id AND (c16_.contentleaf_contentbranch_id = 1)
INNER JOIN widgetgeneral w8_
INNER JOIN widgetabstract w17_ ON w8_.widgetabstract_id = w17_.widgetabstract_id AND (w17_.widgetabstract_contentelement_id = c2_.contentelement_id AND w17_.widgetabstract_discriminator IN ('general') AND w17_.widgetabstract_state = 'preview')
INNER JOIN widgetgeneral w18_
INNER JOIN widgetabstract w19_ ON w18_.widgetabstract_id = w19_.widgetabstract_id AND (w19_.widgetabstract_contentleaf_id = c16_.contentleaf_id AND w19_.widgetabstract_discriminator IN ('general') AND w19_.widgetabstract_state = 'preview')
LEFT JOIN picture p5_ ON t0_.tree_picture_id = p5_.picture_id
LEFT JOIN tree_misc t6_ ON t0_.tree_id = t6_.tree_misc_tree_id AND (t6_.tree_misc_attributetype_key = 'flagId')
LEFT JOIN tree_misc t7_ ON t4_.tree_id = t7_.tree_misc_tree_id AND (t7_.tree_misc_attributetype_key = 'flagId')
LEFT JOIN tree_misc t10_ ON t0_.tree_id = t10_.tree_misc_tree_id AND (t10_.tree_misc_attributetype_key = 'latitude')
LEFT JOIN tree_misc t11_ ON t0_.tree_id = t11_.tree_misc_tree_id AND (t11_.tree_misc_attributetype_key = 'longitude')
WHERE w17_.widgetabstract_visibility = 'active' OR (w17_.widgetabstract_visibility = 'parent' AND w19_.widgetabstract_visibility = 'active')
我們試圖升級以及完整的空白安裝。打開和關閉所有sql模式並查詢優化器選項。如果你需要更多的信息或服務器變量讓我知道。
OS:的Debian GNU/Linux的8(傑西) 服務器版本爲:5.7.14-7-LOG的Percona服務器(GPL),推出 '7',修訂 '083e298'
也許你有一個提示我們缺少什麼。
編輯: 增加配置
[mysqld]
port = 3306
user = mysql
socket = /var/run/mysqld/mysqld.sock
pid-file = /var/run/mysqld/mysqld.pid
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
max_connect_errors = 1000000
log-error = /var/log/mysql/error.log
skip-external-locking
myisam-recover-options = BACKUP
character-set-server = utf8
collation-server = utf8_general_ci
interactive_timeout = 28800
wait_timeout = 28800
skip-name-resolve
group_concat_max_len = 268435456
innodb_file_per_table
innodb_buffer_pool_size = 48G
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 1
innodb_data_file_path = ibdata1:2G:autoextend
innodb_log_file_size = 256M
innodb_log_buffer_size = 64M
innodb_file_format = barracuda
innodb_flush_method = O_DIRECT[mysqld_safe]
syslog
numa_interleave
# Per Thread
sort_buffer_size = 4M
read_buffer_size = 2M
# Cache/connection relevant
thread_cache_size = 850
table_open_cache = 4048
max_connections = 1300
# MyISAM settings (also valid for queries with temporary tables)
key_buffer_size = 128M
myisam_sort_buffer_size = 16M
# Misc
max_allowed_packet = 256M
max_heap_table_size = 16M
thread_stack = 192K
tmp_table_size = 16M
# Query cache
query_cache_limit = 5M
query_cache_size = 4024M
server-id = 102
log_bin = /var/log/mysql/mysql-bin.log
binlog_format = mixed
expire_logs_days = 10
max_binlog_size = 100M
# enforce syncing of every transation to binlog (crash safe, with bbu this should be fast)
sync_binlog = 1
sync_relay_log = 1
sync_master_info = 1
sync_relay_log_info = 1
relay-log = mysqld-relay-bin
skip-slave-start
log-slave-updates
slow_query_log = 1
slow_query_log_file = /var/log/mysql/mysql-slow.log
long_query_time = 1
log-queries-not-using-indexes
MySQL配置文件會很好,特別是'innodb_buffer_pool_size'的值。添加索引不會使查詢工作更快,就像那樣.. – Mjh
add config @Mjh - innodb_buffer_pool_size站在48G,但也嘗試了一個完整的空白配置 – tom
你有5.5'EXPLAIN'嗎?這可能會更容易看出哪些優化出了問題。 –