dongmeng2509 2016-11-08 03:08
浏览 33

在MySQL中等于不返回行,在where子句中什么都不替换

Short Summary: Running in a Drupal environment, I have a query, which returns an empty result set, unless I run some kind of command on the result of an inner select. This can be Trim, replace, upper.

All the unneeded fields have been removed from the select, so I only have the relevant part of the query left.

mysql> SELECT HEX(taxonomy_term_field_data_node_field_data.name)  
   FROM node_field_data 
   LEFT JOIN (SELECT td.*, tn.nid AS nid 
              FROM taxonomy_term_field_data td
              LEFT JOIN taxonomy_index tn ON tn.tid = td.tid
              WHERE (td.vid IN ('category'))
             ) taxonomy_term_field_data_node_field_data
   ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid  
   WHERE (taxonomy_term_field_data_node_field_data.name = "Politik");
Empty set (0.01 sec)

It is possible to select from the taxonomy_term_field_data table when it is not in the join (where name = "Politik")?

mysql> SELECT name FROM taxonomy_term_field_data WHERE name = "Politik"; 
+---------+
| name    |
+---------+
| Politik |
+---------+
1 row in set (0.00 sec)

And If I replace nothing with nothing in the query, I get results back: This also work with UPPER on both strings or TRIM.

mysql> SELECT HEX(taxonomy_term_field_data_node_field_data.name) 
       FROM node_field_data 
       LEFT JOIN (SELECT td.*, tn.nid AS nid
                  FROM taxonomy_term_field_data td
                  LEFT JOIN taxonomy_index tn ON tn.tid = td.tid 
                  WHERE (td.vid IN  ('category'))
                 ) taxonomy_term_field_data_node_field_data
       ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid  
       WHERE (REPLACE(taxonomy_term_field_data_node_field_data.name, "", "") = "Politik");
+----------------------------------------------------+
| HEX(taxonomy_term_field_data_node_field_data.name) |
+----------------------------------------------------+
| 506F6C6974696B                                     |
| 506F6C6974696B                                     |
| 506F6C6974696B                                     |
+----------------------------------------------------+
3 rows in set (0.01 sec)

I have also tried and do an update name = trim(name) in the taxonomy_term_field_data table, but that does not work.

One of the queries are using the where and the other a conditional index, but any input on how to fix this is very welcomed.

mysql> explain SELECT taxonomy_term_field_data_node_field_data.name  FROM node_field_data LEFT JOIN (SELECT td.*, tn.nid AS nid             FROM taxonomy_term_field_data td             LEFT JOIN taxonomy_index tn ON tn.tid = td.tid             WHERE (td.vid IN  ('category'))            ) taxonomy_term_field_data_node_field_data          ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid  WHERE (trim(taxonomy_term_field_data_node_field_data.name) = "Politik");
+----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-------------+
| id | select_type | table           | type  | possible_keys                                | key         | key_len | ref                      | rows | Extra       |
+----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-------------+
|  1 | PRIMARY     | node_field_data | index | PRIMARY,node__id__default_langcode__langcode | node__vid   | 4       | NULL                     |   20 | Using index |
|  1 | PRIMARY     | <derived2>      | ref   | <auto_key0>                                  | <auto_key0> | 5       | v15x.node_field_data.nid |   14 | Using where |
|  2 | DERIVED     | td              | ALL   | taxonomy_term__tree,taxonomy_term__vid_name  | NULL        | NULL    | NULL                     | 1404 | Using where |
|  2 | DERIVED     | tn              | ref   | term_node                                    | term_node   | 4       | v15x.td.tid              |    1 | Using index |
+----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-------------+
4 rows in set (0.00 sec)

mysql> explain SELECT taxonomy_term_field_data_node_field_data.name  FROM node_field_data LEFT JOIN (SELECT td.*, tn.nid AS nid             FROM taxonomy_term_field_data td             LEFT JOIN taxonomy_index tn ON tn.tid = td.tid             WHERE (td.vid IN  ('category'))            ) taxonomy_term_field_data_node_field_data          ON node_field_data.nid = taxonomy_term_field_data_node_field_data.nid  WHERE (taxonomy_term_field_data_node_field_data.name = "Politik");
+----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-----------------------+
| id | select_type | table           | type  | possible_keys                                | key         | key_len | ref                      | rows | Extra                 |
+----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-----------------------+
|  1 | PRIMARY     | node_field_data | index | PRIMARY,node__id__default_langcode__langcode | node__vid   | 4       | NULL                     |   20 | Using index           |
|  1 | PRIMARY     | <derived2>      | ref   | <auto_key1>                                  | <auto_key1> | 5       | v15x.node_field_data.nid |   14 | Using index condition |
|  2 | DERIVED     | td              | ALL   | taxonomy_term__tree,taxonomy_term__vid_name  | NULL        | NULL    | NULL                     | 1404 | Using where           |
|  2 | DERIVED     | tn              | ref   | term_node                                    | term_node   | 4       | v15x.td.tid              |    1 | Using index           |
+----+-------------+-----------------+-------+----------------------------------------------+-------------+---------+--------------------------+------+-----------------------+
4 rows in set (0.00 sec)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 运筹学中在线排序的时间在线排序的在线LPT算法
    • ¥30 求一段fortran代码用IVF编译运行的结果
    • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
    • ¥15 lammps拉伸应力应变曲线分析
    • ¥15 C++ 头文件/宏冲突问题解决
    • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
    • ¥50 安卓adb backup备份子用户应用数据失败
    • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
    • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
    • ¥30 python代码,帮调试,帮帮忙吧