[MDEV-14164] Unknown column error when adding aggregate to function in oracle style procedure FOR loop Created: 2017-10-27 Updated: 2020-08-25 Resolved: 2017-11-09 |
|
| Status: | Closed |
| Project: | MariaDB Server |
| Component/s: | Stored routines |
| Affects Version/s: | 10.0, 10.1, 10.2, 10.3 |
| Fix Version/s: | 10.0.34, 10.1.29, 10.2.11, 10.3.3 |
| Type: | Bug | Priority: | Critical |
| Reporter: | Hartmut Holzgraefe | Assignee: | Oleksandr Byelkin |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Sprint: | 10.2.11 |
| Description |
|
Using this simple setup ...
... the following query works fine when used standalone ...
... but not when used in a procedure / FOR loop context ...
... resulting in ...
Removing just the SUM() aggregate part makes the query/procedure work:
|
| Comments |
| Comment by Alexander Barkov [ 2017-11-07 ] | ||||||||||||||||||
|
The same problem is repeatable on an attempt to open the same cursor two times, without a cursor FOR loop.
The first sp_instr_copen::exec_core() works fine, but the second one fails. | ||||||||||||||||||
| Comment by Alexander Barkov [ 2017-11-07 ] | ||||||||||||||||||
|
The same problem is repeatable with sql_mode=DEFAULT in 10.0, 10.1, 10.2, 10.3.
Also repeatable with COUNT(val) and COUNT( * ) instead of SUM(val). Note, if I remove the second pair of OPEN cur1 and CLOSE cur1, it works fine. | ||||||||||||||||||
| Comment by Alexander Barkov [ 2017-11-07 ] | ||||||||||||||||||
|
Also repeatable if I remove SUM from the inner SELECT, but add DISTINCT to id instead:
| ||||||||||||||||||
| Comment by Alexander Barkov [ 2017-11-07 ] | ||||||||||||||||||
|
The same problem is repeatable without a CURSOR, if I do a direct SELECT inside the SP and call the SP two times:
Notice, the first CALL works fine, while the second CALL fails on the same error:
Note, if I change the equality a.id=b.id to some other comparison predicate, e.g. to:
it starts to work fine. | ||||||||||||||||||
| Comment by Alexander Barkov [ 2017-11-07 ] | ||||||||||||||||||
|
If I issue this command:
all problems disappear. | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
Test suite in format of test suite put here to avoid fixing it each time
| ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
cause of the problem is <exists outer expr> which is not supposed to be reprepared but it is... | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
I was not right, the problem is in the field the <exists outer expr> refer | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
The problem is that name resolution context (made during pullout) refer on not opened table (alias b) | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
| ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
It do not depend on derived tables:
| ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
oops, above I removed not derived which causes problem Actually distinct just make it non mergible, so problem is that there is materialazed derived and it is not processed | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
Converted to IN manually it works:
| ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-07 ] | ||||||||||||||||||
|
Temporary table looks like created, but somehow Item points in other place | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-08 ] | ||||||||||||||||||
|
Name resolution context of a.id field refers to table b (which is OK, because it was in the inner query) but upper name resolution context set to NULL which prevent resolving. | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-08 ] | ||||||||||||||||||
|
Name resolution created during "pull-out". It advance next name resolution but uses original table list... | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-08 ] | ||||||||||||||||||
|
Try to use table list of the place where it was break other tests. | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-08 ] | ||||||||||||||||||
|
The problem is that fix_after_pullout() used for 2 purposes: | ||||||||||||||||||
| Comment by Oleksandr Byelkin [ 2017-11-08 ] | ||||||||||||||||||
|
github tree: bb-10.0- revision-id: cfb314a13b4187e8bb2d3b2ba0f48270e07c61be (mariadb-10.0.33-10-gcfb314a13b4)
Make differentiation between pullout for merge and pulout of outer field during exists2in transformation. — |