Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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 IN关键字小写并与查询结合时不起作用_Mysql_Sql - Fatal编程技术网

Mysql IN关键字小写并与查询结合时不起作用

Mysql IN关键字小写并与查询结合时不起作用,mysql,sql,Mysql,Sql,运行Mysql的服务器(@@version:5.7.29-32-57) 在SQL查询中使用IN关键字时,我注意到一些奇怪的事情 如果在中使用小写形式的,查询将无法正常运行,我无法理解原因 以下是一些例子: select id_g_type from g_type where g_type_parent = '5'; +-----------+ | id_g_type | +-----------+ | 6 | | 8 | |

运行Mysql的服务器(@@version:5.7.29-32-57)

在SQL查询中使用IN关键字时,我注意到一些奇怪的事情

如果在中使用小写形式的
,查询将无法正常运行,我无法理解原因

以下是一些例子:

    select id_g_type 
      from g_type 
     where g_type_parent = '5';
+-----------+
| id_g_type |
+-----------+
|         6 |
|         8 |
|        22 |
+-----------+
3 rows in set (0.00 sec)
现在,当我尝试在
中使用小写和大写时:

select id_g_doc 
  from g_doc 
 where g_doc_folder = '782' 
   and g_doc_type in 
       (select id_g_type from g_type where g_type_parent='5');

Empty set (0.00 sec)

这是一个bug还是我遗漏了什么?

你能把这个问题一五一十地重现一下吗:如果得到确认,这将是MySQL中的一个主要bug。这里不能重现:你使用的是官方的MySQL客户端吗?对我来说很好。See看起来有问题,但是顺便说一句,这个查询很可能作为一个连接运行得很快。像in、减号这样的集合逻辑的性能可能不太好,许多集合逻辑不使用索引和连接。或者,一个相关的子查询“where exists(…)”。然而,幸运的是,一个好的优化器会使您的查询与这些查询一样运行。如果join查询可以返回重复项,其他查询有时可能会消除重复项,而不需要使用DISTINCT或类似的方法。您是否可以将该问题复制出来:如果确认,这将是MySQL中的一个主要错误。此处无法复制:您使用的是官方MySQL客户端吗?对我来说很好。See看起来有问题,但是顺便说一句,这个查询很可能作为一个连接运行得很快。像in、减号这样的集合逻辑的性能可能不太好,许多集合逻辑不使用索引和连接。或者,一个相关的子查询“where exists(…)”。然而,幸运的是,一个好的优化器会使您的查询与这些查询一样运行。如果联接查询可以返回重复项,那么其他查询有时可能会消除它们,而不需要使用DISTINCT等。
select id_g_doc 
  from g_doc 
 where g_doc_folder = '782' 
   and g_doc_type in 
       (select id_g_type from g_type where g_type_parent='5');

Empty set (0.00 sec)
select id_g_doc 
  from g_doc 
 where g_doc_folder = '782' 
   and g_doc_type IN
       (select id_g_type from g_type where g_type_parent='5');
+----------+
| id_g_doc |
+----------+
|      693 |
|      694 |
+----------+
2 rows in set (0.00 sec)