|
Thanks for the report and test case.
Here is the exact same test case, only in one file suitable for MTR:
DROP DATABASE IF EXISTS mdev12780;
|
CREATE DATABASE mdev12780;
|
USE mdev12780;
|
|
CREATE TABLE `tbl_clientes` (
|
`id` int(11) NOT NULL,
|
`id_campanya` int(11) NOT NULL DEFAULT '0',
|
`id_tipo` int(11) NOT NULL DEFAULT '0',
|
`nombre` varchar(255) NOT NULL DEFAULT '',
|
`nombre1` varchar(255) NOT NULL DEFAULT '',
|
`nombre2` varchar(255) NOT NULL DEFAULT '',
|
`cif` varchar(255) NOT NULL DEFAULT '',
|
`comentarios` text NOT NULL,
|
`corriente` varchar(255) NOT NULL DEFAULT '',
|
`contable` varchar(255) NOT NULL DEFAULT '',
|
`diapago` int(11) NOT NULL DEFAULT '0',
|
`direccion` varchar(255) NOT NULL DEFAULT '',
|
`id_pais` int(11) NOT NULL DEFAULT '0',
|
`id_provincia` int(11) NOT NULL DEFAULT '0',
|
`id_poblacion` int(11) NOT NULL DEFAULT '0',
|
`id_codpostal` int(11) NOT NULL DEFAULT '0',
|
`nombre_pais` varchar(255) NOT NULL DEFAULT '',
|
`nombre_provincia` varchar(255) NOT NULL DEFAULT '',
|
`nombre_poblacion` varchar(255) NOT NULL DEFAULT '',
|
`nombre_codpostal` varchar(255) NOT NULL DEFAULT '',
|
`email` varchar(255) NOT NULL DEFAULT '',
|
`web` varchar(255) NOT NULL DEFAULT '',
|
`tel_fijo` varchar(255) NOT NULL DEFAULT '',
|
`tel_movil` varchar(255) NOT NULL DEFAULT '',
|
`fax` varchar(255) NOT NULL DEFAULT ''
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
CREATE TABLE `tbl_empleados` (
|
`id` int(11) NOT NULL,
|
`nombre` varchar(255) NOT NULL DEFAULT '',
|
`nombre1` varchar(255) NOT NULL DEFAULT '',
|
`nombre2` varchar(255) NOT NULL DEFAULT '',
|
`cargo` varchar(255) NOT NULL DEFAULT '',
|
`comentarios` text NOT NULL,
|
`direccion` varchar(255) NOT NULL DEFAULT '',
|
`id_pais` int(11) NOT NULL DEFAULT '0',
|
`id_provincia` int(11) NOT NULL DEFAULT '0',
|
`id_poblacion` int(11) NOT NULL DEFAULT '0',
|
`id_codpostal` int(11) NOT NULL DEFAULT '0',
|
`nombre_pais` varchar(255) NOT NULL DEFAULT '',
|
`nombre_provincia` varchar(255) NOT NULL DEFAULT '',
|
`nombre_poblacion` varchar(255) NOT NULL DEFAULT '',
|
`nombre_codpostal` varchar(255) NOT NULL DEFAULT '',
|
`email` varchar(255) NOT NULL DEFAULT '',
|
`web` varchar(255) NOT NULL DEFAULT '',
|
`tel_fijo` varchar(255) NOT NULL DEFAULT '',
|
`tel_movil` varchar(255) NOT NULL DEFAULT '',
|
`fax` varchar(255) NOT NULL DEFAULT ''
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
INSERT INTO `tbl_empleados` (`id`, `nombre`, `nombre1`, `nombre2`, `cargo`, `comentarios`, `direccion`, `id_pais`, `id_provincia`, `id_poblacion`, `id_codpostal`, `nombre_pais`, `nombre_provincia`, `nombre_poblacion`, `nombre_codpostal`, `email`, `web`, `tel_fijo`, `tel_movil`, `fax`) VALUES
|
(1, 'Josep Sanz', '', '', '', '', '', 0, 0, 0, 0, '', '', '', '', '', '', '', '', '');
|
|
CREATE TABLE `tbl_ficheros` (
|
`id` int(11) NOT NULL,
|
`id_aplicacion` int(11) NOT NULL DEFAULT '0',
|
`id_registro` int(11) NOT NULL DEFAULT '0',
|
`id_usuario` int(11) NOT NULL DEFAULT '0',
|
`datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
|
`fichero` varchar(255) NOT NULL DEFAULT '',
|
`fichero_file` varchar(255) NOT NULL DEFAULT '',
|
`fichero_size` int(11) NOT NULL DEFAULT '0',
|
`fichero_type` varchar(255) NOT NULL DEFAULT '',
|
`search` mediumtext NOT NULL,
|
`indexed` int(11) NOT NULL DEFAULT '0',
|
`retries` int(11) NOT NULL DEFAULT '0'
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
INSERT INTO `tbl_ficheros` (`id`, `id_aplicacion`, `id_registro`, `id_usuario`, `datetime`, `fichero`, `fichero_file`, `fichero_size`, `fichero_type`, `search`, `indexed`, `retries`) VALUES
|
(1, 10, 1, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(2, 10, 2, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(3, 10, 3, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(4, 10, 4, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(5, 10, 5, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(6, 10, 6, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(7, 10, 7, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(8, 10, 8, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(9, 10, 9, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0),
|
(10, 10, 10, 0, '0000-00-00 00:00:00', '', '', 0, '', '', 0, 0);
|
|
CREATE TABLE `tbl_registros_i` (
|
`id` int(11) NOT NULL,
|
`id_aplicacion` int(11) NOT NULL DEFAULT '0',
|
`id_registro` int(11) NOT NULL DEFAULT '0',
|
`id_usuario` int(11) NOT NULL DEFAULT '0',
|
`datetime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
INSERT INTO `tbl_registros_i` (`id`, `id_aplicacion`, `id_registro`, `id_usuario`, `datetime`) VALUES
|
(1, 10, 1, 38, '0000-00-00 00:00:00'),
|
(2, 10, 2, 38, '0000-00-00 00:00:00'),
|
(3, 10, 3, 38, '0000-00-00 00:00:00'),
|
(4, 10, 4, 38, '0000-00-00 00:00:00'),
|
(5, 10, 5, 38, '0000-00-00 00:00:00'),
|
(6, 10, 6, 38, '0000-00-00 00:00:00'),
|
(7, 10, 7, 38, '0000-00-00 00:00:00'),
|
(8, 10, 8, 38, '0000-00-00 00:00:00'),
|
(9, 10, 9, 38, '0000-00-00 00:00:00'),
|
(10, 10, 10, 38, '0000-00-00 00:00:00');
|
|
CREATE TABLE `tbl_usuarios` (
|
`id` int(11) NOT NULL,
|
`id_grupo` int(11) NOT NULL DEFAULT '0',
|
`id_aplicacion` int(11) NOT NULL DEFAULT '0',
|
`id_registro` int(11) NOT NULL DEFAULT '0',
|
`activo` int(11) NOT NULL DEFAULT '0',
|
`login` varchar(255) NOT NULL DEFAULT '',
|
`password` varchar(255) NOT NULL DEFAULT '',
|
`hora_ini` time NOT NULL DEFAULT '00:00:00',
|
`hora_fin` time NOT NULL DEFAULT '00:00:00',
|
`dias_sem` varchar(255) NOT NULL DEFAULT ''
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
|
|
INSERT INTO `tbl_usuarios` (`id`, `id_grupo`, `id_aplicacion`, `id_registro`, `activo`, `login`, `password`, `hora_ini`, `hora_fin`, `dias_sem`) VALUES
|
(38, 0, 31, 1, 0, 'sanz', '', '00:00:00', '00:00:00', '');
|
|
ALTER TABLE `tbl_clientes`
|
ADD PRIMARY KEY (`id`),
|
ADD KEY `id_campanya` (`id_campanya`),
|
ADD KEY `id_pais` (`id_pais`),
|
ADD KEY `id_provincia` (`id_provincia`),
|
ADD KEY `id_poblacion` (`id_poblacion`),
|
ADD KEY `id_codpostal` (`id_codpostal`);
|
|
ALTER TABLE `tbl_empleados`
|
ADD PRIMARY KEY (`id`),
|
ADD KEY `id_pais` (`id_pais`),
|
ADD KEY `id_provincia` (`id_provincia`),
|
ADD KEY `id_poblacion` (`id_poblacion`),
|
ADD KEY `id_codpostal` (`id_codpostal`);
|
|
ALTER TABLE `tbl_ficheros`
|
ADD PRIMARY KEY (`id`),
|
ADD KEY `ficheros` (`id_aplicacion`,`id_registro`),
|
ADD KEY `ficheros2` (`indexed`,`retries`);
|
|
ALTER TABLE `tbl_registros_i`
|
ADD PRIMARY KEY (`id`),
|
ADD KEY `id_usuario` (`id_usuario`),
|
ADD KEY `registros` (`id_aplicacion`,`id_registro`),
|
ADD KEY `registros3` (`id_aplicacion`,`id_registro`,`id_usuario`);
|
|
ALTER TABLE `tbl_usuarios`
|
ADD PRIMARY KEY (`id`),
|
ADD KEY `id_grupo` (`id_grupo`),
|
ADD KEY `usuarios` (`id_aplicacion`,`id_registro`);
|
|
ALTER TABLE `tbl_clientes`
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
|
|
ALTER TABLE `tbl_empleados`
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
|
|
ALTER TABLE `tbl_ficheros`
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
|
|
ALTER TABLE `tbl_registros_i`
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;
|
|
ALTER TABLE `tbl_usuarios`
|
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=139;COMMIT;
|
|
SELECT usuario FROM (
|
SELECT a.id id,
|
a.id_registro id_registro,
|
a.id_aplicacion id_aplicacion,
|
d.id id_usuario,
|
d.id_grupo id_grupo,
|
e.datetime datetime,
|
CONCAT(
|
CASE d.id_aplicacion
|
WHEN '1' THEN (SELECT nombre FROM tbl_clientes WHERE id=d.id_registro)
|
WHEN '31' THEN (SELECT nombre FROM tbl_empleados WHERE id=d.id_registro)
|
END,
|
' (',
|
d.login,
|
')'
|
) usuario
|
FROM tbl_ficheros a
|
LEFT JOIN tbl_registros_i e ON e.id_aplicacion=a.id_aplicacion AND e.id_registro=a.id_registro
|
LEFT JOIN tbl_usuarios d ON e.id_usuario=d.id
|
) z
|
WHERE id_usuario='38';
|
|
DROP DATABASE mdev12780;
|
|
Actual result
|
usuario
|
Josep Sanz (sanz)
|
Josep Sanz (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz) (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz) (sanz) (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz)
|
Josep Sanz (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz) (sanz)
|
|
Expected result
|
usuario
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Josep Sanz (sanz)
|
Reproducible with derived_merge=on or when the subquery `z` is wrapped into a merge view.
sanz, thus, for now a workaround could be to set derived_merge=off.
|