mysql 不正确的数据名_MySQL返回不正确的数据?

Django社区最近出现了一个关于MySQL测试的问题(使用MyISAM)。

这是django票证:http://code.djangoproject.com/ticket/14661

Django的一位核心开发人员提出了这个测试,我们很多人都能够复制它。任何人都有猜测我们在这里遇到什么?它仅仅是MySQL中的一个错误还是我错过了一些东西?

以下是测试代码和查询:

DROP TABLE IF EXISTS `testapp_tag`;

CREATE TABLE `testapp_tag` (

`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY,

`name` varchar(10) NOT NULL,

`parent_id` integer

);

INSERT INTO `testapp_tag` (`name`, `parent_id`) VALUES ("t1", NULL);

INSERT INTO `testapp_tag` (`name`, `parent_id`) VALUES ("t2", 1);

INSERT INTO `testapp_tag` (`name`, `parent_id`) VALUES ("t3", 1);

INSERT INTO `testapp_tag` (`name`, `parent_id`) VALUES ("t4", 3);

INSERT INTO `testapp_tag` (`name`, `parent_id`) VALUES ("t5", 3);

SELECT `testapp_tag`.`id`, `testapp_tag`.`name`, `testapp_tag`.`parent_id` FROM `testapp_tag` WHERE NOT ((`testapp_tag`.`id` IN (SELECT U0.`id` FROM `testapp_tag` U0 LEFT OUTER JOIN `testapp_tag` U1 ON (U0.`id` = U1.`parent_id`) WHERE U1.`id` IS NULL) AND `testapp_tag`.`id` IS NOT NULL)) ORDER BY `testapp_tag`.`name` ASC;

SELECT `testapp_tag`.`id`, `testapp_tag`.`name`, `testapp_tag`.`parent_id` FROM `testapp_tag` WHERE NOT ((`testapp_tag`.`id` IN (SELECT U0.`id` FROM `testapp_tag` U0 LEFT OUTER JOIN `testapp_tag` U1 ON (U0.`id` = U1.`parent_id`) WHERE U1.`id` IS NULL) AND `testapp_tag`.`id` IS NOT NULL)) ORDER BY `testapp_tag`.`name` ASC;这是输出:

mysql> SELECT `testapp_tag`.`id`, `testapp_tag`.`name`, `testapp_tag`.`parent_id` FROM `testapp_tag` WHERE NOT ((`testapp_tag` .`id` IN (SELECT U0.`id` FROM `testapp_tag` U0 LEFT OUTER JOIN `testapp_tag` U1 ON (U0.`id` = U1.`parent_id`) WHERE U1.`id` IS NULL) AND `testapp_tag`.`id` IS NOT NULL)) ORDER BY `testapp_tag`.`name` ASC;

+----+------+-----------+

| id | name | parent_id |

+----+------+-----------+

| 1 | t1 | NULL |

| 3 | t3 | 1 |

| 5 | t5 | 3 |

+----+------+-----------+

3 rows in set (0.00 sec)

mysql> SELECT `testapp_tag`.`id`, `testapp_tag`.`name`, `testapp_tag`.`parent_id` FROM `testapp_tag` WHERE NOT ((`testapp_tag` .`id` IN (SELECT U0.`id` FROM `testapp_tag` U0 LEFT OUTER JOIN `testapp_tag` U1 ON (U0.`id` = U1.`parent_id`) WHERE U1.`id` IS NULL) AND `testapp_tag`.`id` IS NOT NULL)) ORDER BY `testapp_tag`.`name` ASC;

+----+------+-----------+

| id | name | parent_id |

+----+------+-----------+

| 1 | t1 | NULL |

| 3 | t3 | 1 |

+----+------+-----------+

2 rows in set (0.01 sec)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值