我在使用mysql时遇到了一些问题。请参阅下一个脚本,我将在其中创建一个表、插入一些数据、查询、更改数据,然后再次查询。
考虑这个脚本:
#Create the table
DROP TABLE IF EXISTS T;
CREATE TABLE `T` (
`id` BIGINT(20) UNSIGNED NOT NULL,
`x` VARCHAR(50) COLLATE utf8_bin DEFAULT NULL,
`y` VARCHAR(15) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `d6fe1d0be6347b8ef2427fa629c04485` (`x`),
KEY `ee16755af8c89d0c26540daf7a0fe1b3` (`y`)
) ENGINE=MYISAM DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
#Add two lines
INSERT INTO T VALUES (1,'login','read'), (3,'','read');
#Query 1: expected 1 line, got 1 line
SELECT * FROM T WHERE
`y` = 'read' AND
(
('login' = '' AND `x` = '') OR
(`x` != '' && 'login' REGEXP `x`)
);
#Query 2: expected 1 line, got 2 line
SELECT * FROM T WHERE
`y` = 'read' AND
(
('login' = '' AND `x` = '') OR
('login' REGEXP `x`)
);
#Invert field x
UPDATE T SET `x` = '' WHERE id = 1;
UPDATE T SET `x` = 'login' WHERE id = 3;
#Another time, Query 1: expected 1 line, got 1 line
SELECT * FROM T WHERE
`y` = 'read' AND
(
('login' = '' AND `x` = '') OR
(`x` != '' && 'login' REGEXP `x`)
);
#Another time, Query 2: expected 1 line, got 1 line
SELECT * FROM T WHERE
`y` = 'read' AND
(
('login' = '' AND `x` = '') OR
('login' REGEXP `x`)
);
它将输出:
id x y
1 login read
id x y
1 login read
3 read
id x y
3 login read
id x y
3 login read
我认为这是一个错误。