开发有一个sql,在a实例上执行正常执行,b实例上执行报错。
报错信息
ERROR 1093 (HY000): You can’t specify target table ‘ver’ for update in FROM clause
对比下2个实例的配置
Variable b a
========================= ========================= =========================
back_log 250 850
basedir /usr/local/mysql /usr/local/mysql-5.7.11
character_set_client utf8mb4 utf8
character_set_connection utf8mb4 utf8
character_set_database utf8mb4 utf8
character_set_results utf8mb4 utf8
character_set_server utf8mb4 utf8
character_sets_dir /usr/local/mysql/share... /usr/local/mysql-5.7.1...
collation_connection utf8mb4_unicode_ci utf8_general_ci
collation_database utf8mb4_unicode_ci utf8_general_ci
collation_server utf8mb4_unicode_ci utf8_general_ci
datadir /home/mysql/data/ /home/mysql_3306/
default_password_lifetime 360 0
expire_logs_days 7 0
general_log_file /home/mysql/data/db-10... /home/mysql_3306/10923...
have_openssl YES DISABLED
have_ssl YES DISABLED
have_symlink YES DISABLED
host_cache_size 653 803
hostname db-10921102 10923183-eletestserver
innodb_buffer_pool_ins... 8 1
innodb_buffer_pool_size 4294967296 134217728
innodb_flush_method O_DIRECT
innodb_log_file_size 1073741824 50331648
innodb_page_cleaners 4 1
innodb_use_native_aio OFF ON
innodb_version 5.7.10 5.7.11
lc_messages_dir /usr/local/mysql/share/ /usr/local/mysql-5.7.1...
log_bin_basename /home/mysql/data/binlog /home/mysql_3306/bin
log_bin_index /home/mysql/data/binlo... /home/mysql_3306/bin.i...
log_bin_trust_function... ON OFF
log_error /home/mysql/data/10921... /home/mysql_3306/mysql...
max_allowed_packet 629145600 4194304
max_connections 1000 4000
performance_schema_max... 192 193
pid_file /home/mysql/data/10921... /home/mysql_3306/mysql...
plugin_dir /usr/local/mysql/lib/p... /usr/local/mysql-5.7.1...
server_uuid 7fc12caf-88ac-11e8-873... 260ba4db-bd00-11e9-bd8...
slow_query_log_file /home/mysql/data/db-10... /home/mysql_3306/10923...
socket /tmp/mysql.sock /home/mysql_3306/mysql...
sql_mode STRICT_TRANS_TABLES,NO... STRICT_TRANS_TABLES,NO...
ssl_ca ca.pem
ssl_cert server-cert.pem
ssl_key server-key.pem
thread_cache_size 18 48
tx_isolation REPEATABLE-READ READ-COMMITTED
version 5.7.10-log 5.7.11-log
version_comment Source distribution MySQL Community Server...
version_compile_os Linux linux-glibc2.5
看到在a上是正常,b是有错误提示,2个实例有几个重要的参数不一致。
sql_mode,tx_isolation,version_comment,把b的这2个参数设置一致后,也是报错,看来不是这2个参数导致的.
查看optimizer_switch参数show variables like '%switch%'; +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Variable_name | Value | +------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | optimizer_switch | index_merge=on,index_merge_union=on,index_merge_sort_union=on,index_merge_intersection=on,engine_condition_pushdown=on,index_condition_pushdown=on,mrr=on,mrr_cost_based=on,block_nested_loop=on,batched_key_access=off,materialization=on,semijoin=on,loosescan=on,firstmatch=on,duplicateweedout=on,subquery_materialization_cost_based=on,use_index_extensions=on,condition_fanout_filter=on,derived_merge=on| +------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2边也是一样的,但是实例的版本是不一样的,并且语句是自查询更新,通过搜索文档发现
However, beware that from MySQL 5.7.6 and onward, the optimiser may optimise out the subquery, and still give you the error. Luckily, the optimizer_switch variable can be used to switch off this behaviour; although I couldn’t recommend doing this as anything more than a short term fix, or for small one-off tasks.
尝试关闭自查询展开,sql可以执行,但是不建议这么做,还是建议该sql,把sql简化处理