Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.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
LIKE CONCAT中奇怪的MySQL 5.7行为_Mysql_Collation_Mysql 5.7 - Fatal编程技术网

LIKE CONCAT中奇怪的MySQL 5.7行为

LIKE CONCAT中奇怪的MySQL 5.7行为,mysql,collation,mysql-5.7,Mysql,Collation,Mysql 5.7,我在Mysql 5.7中遇到了一个非常奇怪的行为。它不会发生在5.6或8.0上,只有5.7 我有一个疑问: SELECT r.identificador, rh.id_reserva_habitacion, h.id_habitacion, (SELECT identificador FROM reservas WHERE identificador LIKE CONCAT(r.identificador, '.%') LIMIT 1) AS modificada FROM

我在Mysql 5.7中遇到了一个非常奇怪的行为。它不会发生在5.6或8.0上,只有5.7

我有一个疑问:

SELECT
    r.identificador, rh.id_reserva_habitacion, h.id_habitacion,
    (SELECT identificador FROM reservas WHERE identificador LIKE CONCAT(r.identificador, '.%') LIMIT 1) AS modificada
FROM
    (`reservas` r, `reservas_habitaciones` rh, `habitaciones` h)
WHERE
    r.identificador = 'XXA' AND r.identificador = rh.identificador AND h.id_habitacion = rh.id_habitacion
GROUP BY
    rh.id_reserva_habitacion
这是测试它的最小转储:

CREATE TABLE IF NOT EXISTS `habitaciones` (
  `id_habitacion` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `id_hotel` int(10) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`id_habitacion`)
) ENGINE=MyISAM AUTO_INCREMENT=4474 DEFAULT CHARSET=utf8;

INSERT INTO `habitaciones` (`id_habitacion`, `id_hotel`) VALUES
(1, 200),
(2, 200);

CREATE TABLE IF NOT EXISTS `reservas` (
  `identificador` varchar(13) NOT NULL DEFAULT '',
  `timestamp` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`identificador`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

INSERT INTO `reservas` (`identificador`, `timestamp`) VALUES
('XXA', '2020-01-02'),
('XXA.01', '2020-01-01'),
('XXB', '2020-01-01');

CREATE TABLE IF NOT EXISTS `reservas_habitaciones` (
  `id_reserva_habitacion` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `identificador` varchar(13) NOT NULL DEFAULT '',
  `id_habitacion` int(10) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`id_reserva_habitacion`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

INSERT INTO `reservas_habitaciones` (`id_reserva_habitacion`, `identificador`, `id_habitacion`) VALUES
(1, 'XXA', 1),
(2, 'XXB', 1),
(3, 'XXB', 2);
查询应在
modificada
字段上返回值“XXA.01”,但返回NULL

现在是奇怪的部分:

  • 如果我只是从查询中删除
    groupby
    ,它就可以工作了
  • 如果我只是从查询中删除
    habitaciones
    表,它就可以工作了
  • 如果'XXA.01'的值改为'XXA_01',(在查询中为'\u%'),则它可以工作`
  • 如果不是
    CONCAT(r.identificator,'.%')
    而是
    CONCAT('XXA','.%')
    ,则它可以工作
  • 如果我指定了一个排序规则(它应该已经有了),它就可以工作了
  • 如果我删除了
    habitaciones
    中的第二条记录,只留下id“1”,它也可以工作
  • 如果我在5.6或8.0中使用它,它将完美地工作(事实上,它在5.6中一直工作,没有任何问题)
但目前,我不能接受这些解决方案中的任何一个。很明显,查询和数据比这个例子要大,我不想碰这些

我认为这与排序规则或字符集以及'XXA.01'中的点有关,但我不明白查询中的表或行数会如何影响它

我想知道这是关于服务器配置、表、字段、字符集还是一个bug


谢谢

您应该从(
reservas
r,
reservas\u habitaciones
rh,
habitaciones
h)更改为加入。。在…**上,结果与JOINSPLE相同。请为两个版本提供
EXPLAIN-SELECT…
EXPLAIN-FORMAT=JSON-SELECT…
。考虑在BugsMySQL网站上编写一个bug报告。在MariaDB的几个版本上也是可以的。
SELECT
    r.identificador, rh.id_reserva_habitacion, h.id_habitacion,
    (SELECT identificador FROM reservas WHERE identificador LIKE CONCAT(r.identificador, '.%') LIMIT 1) AS modificada
FROM
    (`reservas` r, `reservas_habitaciones` rh, `habitaciones` h)
WHERE
    r.identificador = 'XXA' AND r.identificador = rh.identificador AND h.id_habitacion = rh.id_habitacion
SELECT
    r.identificador, rh.id_reserva_habitacion,
    (SELECT identificador FROM reservas WHERE identificador LIKE CONCAT(r.identificador, '.%') LIMIT 1) AS modificada
FROM
    (`reservas` r, `reservas_habitaciones` rh)
WHERE
    r.identificador = 'XXA' AND r.identificador = rh.identificador
GROUP BY
    rh.id_reserva_habitacion
SELECT
    r.identificador, rh.id_reserva_habitacion, h.id_habitacion,
    (SELECT identificador FROM reservas WHERE identificador LIKE CONCAT(r.identificador, '_%') LIMIT 1) AS modificada
FROM
    (`reservas` r, `reservas_habitaciones` rh, `habitaciones` h)
WHERE
    r.identificador = 'XXA' AND r.identificador = rh.identificador AND h.id_habitacion = rh.id_habitacion
GROUP BY
    rh.id_reserva_habitacion
SELECT
    r.identificador, rh.id_reserva_habitacion, h.id_habitacion,
    (SELECT identificador FROM reservas WHERE identificador LIKE CONCAT('XXA', '.%') LIMIT 1) AS modificada
FROM
    (`reservas` r, `reservas_habitaciones` rh, `habitaciones` h)
WHERE
    r.identificador = 'XXA' AND r.identificador = rh.identificador AND h.id_habitacion = rh.id_habitacion
GROUP BY
    rh.id_reserva_habitacion
SELECT
    r.identificador, rh.id_reserva_habitacion, h.id_habitacion,
    (SELECT identificador FROM reservas WHERE identificador COLLATE utf8_general_ci LIKE CONCAT(r.identificador, '.%') LIMIT 1) AS modificada
FROM
    (`reservas` r, `reservas_habitaciones` rh, `habitaciones` h)
WHERE
    r.identificador = 'XXA' AND r.identificador = rh.identificador AND h.id_habitacion = rh.id_habitacion
GROUP BY
    rh.id_reserva_habitacion