[MDEV-3503] LP:1008773 - Wrong result (NULL instead of a value) with no matching rows, subquery in FROM and HAVING Created: 2012-06-04 Updated: 2015-02-02 Resolved: 2012-10-04 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Bug | Priority: | Minor |
| Reporter: | Elena Stepanova | Assignee: | Timour Katchaounov (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | Launchpad | ||
| Attachments: |
|
| Description |
|
The following query SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1 with 0 rows in t1 and 1 row in t2 produces NULL, NULL on maria/5.3 and maria/5.5. Same happens if t1 is not empty, but the outer SELECT has an impossible WHERE condition. t2 can have more rows too, in which case a subquery should use an aggregate function, e.g. SUM. The same query without t2 produces NULL, 1; maria-5.1, maria-5.2, mysql-5.1, mysql-5.5, mysql-trunk, postgres-8.4.7 return NULL, 1 for both queries. Reproducible with MyISAM and Aria, but not InnoDB. EXPLAIN (with in_to_exists=on, everything else OFF): id select_type table type possible_keys key key_len ref rows filtered Extra
SET optimizer_switch='in_to_exists=on'; CREATE TABLE t1 (a INT) ENGINE=MyISAM;
SELECT MAX(a), ( SELECT 1 FROM t2 ) AS bb FROM t1;
|
| Comments |
| Comment by Sergei Petrunia [ 2012-06-14 ] |
|
Re: Wrong result (NULL instead of a value) with no matching rows, subquery in FROM and HAVING |
| Comment by Rasmus Johansson (Inactive) [ 2012-06-14 ] |
|
Launchpad bug id: 1008773 |