Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySql查询在控制台中优化,但在节点/Python客户端中未优化_Mysql_Mysql Python_Node Mysql - Fatal编程技术网

MySql查询在控制台中优化,但在节点/Python客户端中未优化

MySql查询在控制台中优化,但在节点/Python客户端中未优化,mysql,mysql-python,node-mysql,Mysql,Mysql Python,Node Mysql,我有一个相当复杂的查询,使用了许多连接和not in子句。我已经使用MySql控制台对这个查询进行了优化,我确信在执行计划中没有依赖于的子查询。但是,让我惊讶的是,当我在同一个MySql实例中使用Node和Python客户端执行完全相同的查询时,查询速度要慢得多。通过这些客户端使用explain语句,将显示两个相关子查询。当直接在控制台中发出,而不是通过这样的客户端发出时,为什么会成功地优化同一个查询?如何调试此问题 编辑:请求的详细信息 SELECT@@optimizer\u开关的输出与控制台

我有一个相当复杂的查询,使用了许多连接和
not in
子句。我已经使用MySql控制台对这个查询进行了优化,我确信在执行计划中没有依赖于
的子查询。但是,让我惊讶的是,当我在同一个MySql实例中使用Node和Python客户端执行完全相同的查询时,查询速度要慢得多。通过这些客户端使用
explain
语句,将显示两个
相关子查询。当直接在控制台中发出,而不是通过这样的客户端发出时,为什么会成功地优化同一个查询?如何调试此问题

编辑:请求的详细信息

SELECT@@optimizer\u开关的输出与控制台和python客户端的输出相同:
index\u merge=on,index\u merge\u union=on,index\u merge\u union=on,index\u merge\u intersection=on,engine\u condition\u pushdown=on,index\u condition\u pushdown=on,mrr=on,mrr\u cost\u-based=on,block\u嵌套循环\u-key\u-access=off,物化=on,semijoin=on,loosescan=on,firstmatch=on,duplicatedweedout=on,subquery\u物化\u-cost=on,使用(索引)(扩展)开,条件(扇出)(过滤)开,派生(合并)开

MySql控制台中的执行计划:

+----+-------------+-------------+------------+------+---------------------------------------------------------------------------+---------------------+---------+------+---------+----------+----------------------------------------------------+
| id | select_type | table       | partitions | type | possible_keys                                                             | key                 | key_len | ref  | rows    | filtered | Extra                                              |
+----+-------------+-------------+------------+------+---------------------------------------------------------------------------+---------------------+---------+------+---------+----------+----------------------------------------------------+
|  1 | PRIMARY     | c           | NULL       | ALL  | config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key | NULL                | NULL    | NULL | 1912779 |     5.00 | Using where                                        |
|  1 | PRIMARY     | <derived2>  | NULL       | ALL  | NULL                                                                      | NULL                | NULL    | NULL |  956388 |     1.00 | Using where; Using join buffer (Block Nested Loop) |
|  2 | DERIVED     | c           | NULL       | ALL  | config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key | NULL                | NULL    | NULL | 1912779 |    50.00 | Using where; Using temporary; Using filesort       |
|  4 | UNION       | c           | NULL       | ALL  | NULL                                                                      | NULL                | NULL    | NULL | 1912779 |    10.00 | Using where                                        |
|  4 | UNION       | <derived7>  | NULL       | ALL  | NULL                                                                      | NULL                | NULL    | NULL |  956388 |     1.00 | Using where; Using join buffer (Block Nested Loop) |
|  4 | UNION       | a           | NULL       | ref  | idx_accounts_domain                                                       | idx_accounts_domain | 202     | func |      26 |   100.00 | Using where; Using index                           |
|  9 | SUBQUERY    | c           | NULL       | ALL  | config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key | NULL                | NULL    | NULL | 1912779 |     5.00 | Using where                                        |
|  9 | SUBQUERY    | <derived11> | NULL       | ALL  | NULL                                                                      | NULL                | NULL    | NULL |  956388 |     1.00 | Using where; Using join buffer (Block Nested Loop) |
| 11 | DERIVED     | c           | NULL       | ALL  | config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key | NULL                | NULL    | NULL | 1912779 |    50.00 | Using where; Using temporary; Using filesort       |
|  7 | DERIVED     | c           | NULL       | ALL  | config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key | NULL                | NULL    | NULL | 1912779 |    50.00 | Using where; Using temporary; Using filesort       |
+----+-------------+-------------+------------+------+---------------------------------------------------------------------------+---------------------+---------+------+---------+----------+----------------------------------------------------+
+----+-------------+-------------+------------+------+---------------------------------------------------------------------------+---------------------+---------+------+---------+----------+----------------------------------------------------+
|id |选择|类型|表格|分区|类型|可能的|键|键|列|参考|行|过滤|额外|
+----+-------------+-------------+------------+------+---------------------------------------------------------------------------+---------------------+---------+------+---------+----------+----------------------------------------------------+
|1 |主| c | NULL |所有|配置| idx |路径2,配置| idx |路径|键2,配置| idx |路径|键空|空|空| 1912779 | 5.00 |使用where|
|1 | PRIMARY | NULL | ALL | NULL | NULL | NULL | NULL | 956388 | 1.00 |使用where;使用联接缓冲区(块嵌套循环)|
|2 |派生| c | NULL | ALL |配置| idx | u路径2,配置| idx | u路径2,配置| idx | u路径|键| NULL | NULL | NULL | 1912779 | 50.00 |使用where;使用临时设备;使用文件排序|
|4 | UNION | c | NULL | ALL | NULL | NULL | NULL | NULL | 1912779 | 10.00 |使用where|
|4 | UNION | NULL | ALL | NULL | NULL | NULL | NULL | 956388 | 1.00 |使用where;使用联接缓冲区(块嵌套循环)|
|4 | UNION | a | NULL | ref | idx | u accounts | u domain | idx | u accounts | u domain | 202 | func | 26 | 100.00 |使用where;使用索引|
|9 |子查询| c | NULL | ALL |配置| idx |路径2,配置| idx |路径2,配置| idx |路径|键| NULL | NULL | NULL | 1912779 | 5.00 |使用where|
|9 |子查询| NULL | ALL | NULL | NULL | NULL | NULL | 956388 | 1.00 |使用where;使用联接缓冲区(块嵌套循环)|
|11 |派生| c | NULL | ALL |配置| idx | u路径2,配置| idx | u路径| key | NULL | NULL | 1912779 | 50.00 |使用where;使用临时设备;使用文件排序|
|7 |派生| c | NULL | ALL |配置| idx | u路径2,配置| idx | u路径| key | NULL | NULL | 1912779 | 50.00 |使用where;使用临时设备;使用文件排序|
+----+-------------+-------------+------------+------+---------------------------------------------------------------------------+---------------------+---------+------+---------+----------+----------------------------------------------------+
来自python客户端的执行计划:

[
  (1, 'PRIMARY', 'c', None, 'ALL', 'config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key', None, None, None, 1912779, 5.0, 'Using where'),
  (1, 'PRIMARY', '<derived2>', None, 'ALL', None, None, None, None, 956388, 1.0, 'Using where; Using join buffer (Block Nested Loop)'),
  (2, 'DERIVED', 'c', None, 'ALL', 'config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key', None, None, None, 1912779, 50.0, 'Using where; Using temporary; Using filesort'),
  (4, 'UNION', 'c', None, 'ALL', None, None, None, None, 1912779, 10.0, 'Using where'),
  (4, 'UNION', '<derived7>', None, 'ALL', None, None, None, None, 956388, 1.0, 'Using where; Using join buffer (Block Nested Loop)'),
  (4, 'UNION', 'a', None, 'ref', 'idx_report_settings_domain', 'idx_report_settings_domain', '202', 'func', 26, 100.0, 'Using where; Using index'),
  (9, 'DEPENDENT SUBQUERY', 'c', None, 'ALL', 'config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key', None, None, None, 1912779, 5.0, 'Using where'),
  (9, 'DEPENDENT SUBQUERY', '<derived11>', None, 'ALL', None, None, None, None, 956388, 1.0, 'Using where; Using join buffer (Block Nested Loop)'),
  (11, 'DERIVED', 'c', None, 'ALL', 'config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key', None, None, None, 1912779, 50.0, 'Using where; Using temporary; Using filesort'),
  (7, 'DERIVED', 'c', None, 'ALL', 'config_idx_path2,config_idx_path_key2,config_idx_path,config_idx_path_key', None, None, None, 1912779, 50.0, 'Using where; Using temporary; Using filesort')
]
[
(1,'PRIMARY','c',None','ALL','config_idx_path 2,config_idx_path_key 2,config_idx_path,config_idx_path_key',None,None,None,1912779,5.0,'Using where'),
(1,'PRIMARY','',None,'ALL',None,None,None,956388,1.0,'使用where;使用连接缓冲区(块嵌套循环)',
(2,‘派生’、‘c’、‘无’、‘全部’、‘配置idx路径2、配置idx路径2、配置idx路径、配置idx路径、配置idx路径’,无、无、无、1912779、50.0,’使用where;使用temporary;使用filesort’,
(4,'UNION','c',None','ALL',None,None,None,None,1912779,10.0,'Using where'),
(4,'UNION','None','ALL',None,None,None,None,956388,1.0,'使用where;使用连接缓冲区(块嵌套循环)',
(4,'UNION','a','None','ref','idx_报告设置_域','idx_报告设置_域','202','func',26,100.0',使用where;使用index'),
(9,‘依赖子查询’、‘c’、‘None’、‘ALL’、‘config_idx_path2、config_idx_path2、config_idx_path2、config_idx_path2、config_idx_path2、config_idx_path2、config_idx_path2、config_idx_path2、config_idx_Pat,
(9,'DEPENDENT SUBQUERY','',None,'ALL',None,None,None,956388,1.0,'使用where;使用连接缓冲区(块嵌套循环)',
(11,“派生”、“c”、无、“全部”、“配置idx路径2、配置idx路径”