Menu

#4510 (ok 4.5) QBE generates wrong query

4.4.0
resolved
None
Normal
2015-06-14
2014-08-10
No

When there are three tables in QBE, two of them have relations and one does not, QBE generates following query:

SELECT master.*, slave.*
FROM master
LEFT JOIN qbetest.slave ON master.id = slave.master_id

While it should generate:

SELECT `extra`.*, `master`.*, `slave`.*
FROM `extra`, `slave`
LEFT JOIN `qbetest`.`master` ON `slave`.`master_id` = `master`.`id` ;

Tables to reproduce:

CREATE TABLE IF NOT EXISTS `extra` (
`id` int(11) NOT NULL,
`data` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `master` (
`id` int(11) NOT NULL,
`data` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `slave` (
`id` int(11) NOT NULL,
`master_id` int(11) NOT NULL,
`data` text NOT NULL,
PRIMARY KEY (`id`),
KEY `master_id` (`master_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ALTER TABLE `slave`
ADD CONSTRAINT `slave_ibfk_1` FOREIGN KEY (`master_id`) REFERENCES `master` (`id`);

To reproduce just do a QBE and select extra.*, master.*, slave.* and check display for all of these.

Discussion

  • Ashutosh Dhundhara

    Hi Hugues,
    as per the discussion [0] on mailing list, it was found that user generally needs to display all the rows of the master table even for those there are no matching rows in the slave table. Also it was seen that UI can't help much to deduce the intentions of the user in case of 3 tables.
    But still, the thread is open for discussion.

    [0] https://sourceforge.net/p/phpmyadmin/mailman/message/32679744/

     
  • Hugues Peccatte

    Hugues Peccatte - 2014-11-07
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -1,6 +1,6 @@
     When there are three tables in QBE, two of them have relations and one does not, QBE generates following query:
    
    -SELECT `master`.*, `slave`.*
    +SELECT `master`.\*, `slave`.\*
     FROM `master`
     LEFT JOIN `qbetest`.`slave` ON `master`.`id` = `slave`.`master_id`
    
     
  • Madhura Jayaratne

    • assigned_to: Madhura Jayaratne
     
  • Madhura Jayaratne

    • assigned_to: Madhura Jayaratne --> nobody
     
  • Madhura Jayaratne

    • assigned_to: Madhura Jayaratne
     
  • Madhura Jayaratne

    • summary: QBE generates wrong query --> (ok 4.5) QBE generates wrong query
    • status: open --> resolved
    • Group: Latest_Git --> 4.4.0