Home >Database >Mysql Tutorial >mysql in函数结果不同预期,异常null处理_MySQL

mysql in函数结果不同预期,异常null处理_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 13:35:101065browse

bitsCN.com

mysql in函数结果不同预期,异常null处理

 

好几次合服后,游戏里面的账号达到了100w上,整点的一些操作导致服务器响应很慢,后来发现,作为研发方我们没必要存没有实际内容的账号,那游戏来说就是,没必要存没有角色的账号,毕竟有角色的账号有的服甚至到不了百分之一。

 

于是决定删除这些没角色的账号。

 

select count(*) from user;

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

| count(*) |

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

|  1004897 | 

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

 select count(*) from player;

 

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

| count(*) |

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

|    57342 | 

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

delete from user where id not in (select user_id from player) 

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

| count(*) |

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

|        0 | 

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

 

怎么想都觉得纳闷,因为user的id跟player的user_id都是唯一的

 

无意间想到null的情况。

 

一查果然

 

select user_id from player

 

里面 有null的情况存在导致结果出现异常。

 

删除 那条记录后一切正常

 

看来null不近在语言中需要特殊考虑,在数据库中也是个比较特殊的情况。。

 

bitsCN.com
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn