Hi, Oleksandr! On Mar 16, Oleksandr Byelkin wrote:
On Mar 16, OleksandrByelkin wrote:
revision-id: 72b709ac7503ae6dd2b5e9049322fefb90b0ebbe (mariadb-10.1.12-16-g72b709a) parent(s): 9b53d84d14a9b031d193f6beae382a232aa738e3 committer: Oleksandr Byelkin timestamp: 2016-03-16 19:49:17 +0100 message:
MDEV-9701: CREATE VIEW with GROUP BY or ORDER BY and constant produces invalid definition
Fixed printing integer constant in the ORDER clause (MySQL solution) Removed workaround for double resolving counter in the ORDER.
diff --git a/sql/sql_select.cc b/sql/sql_select.cc index fff24b9..f14e8b1 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -21874,7 +21874,11 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, */ if (order_item->type() == Item::INT_ITEM && order_item->basic_const_item()) { /* Order by position */ - uint count= (uint) order_item->val_int(); + uint count; + if (order->counter_used) how can this happen? we merge view and so its ORDER BY first we resolve it in view then in outer query. It actually works (I am not sure if I should include also following test:
create table t1 (a int, b int); insert into t1 values (1,2), (2,1); create view v1 as select a, b from t1 order by 1; select b,a from v1; b a 2 1 1 2
Did it work before this your change? If yes - how?
Actually I can make above even more efficient, just exit in case if resolving already done. Try it?
If you do - do it in a separate commit, please
+ count= order->counter; // counter was once resolved + else + count= (uint) order_item->val_int(); if (!count || count > fields.elements) { my_error(ER_BAD_FIELD_ERROR, MYF(0), diff --git a/sql/sql_union.cc b/sql/sql_union.cc index c835083..8145cec 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc bool st_select_lex::cleanup() { bool error= FALSE; DBUG_ENTER("st_select_lex::cleanup()");
+ cleanup_order(order_list.first); + cleanup_order(group_list.first); why is it needed? For PS and exactly for PS with "ORDER BY ?" to make new resolving for re-execution.
Why would one need to redo it? The number will always resolve to the same Item, won't it? One can safely do it only once, it seems. Regards, Sergei Chief Architect MariaDB and security@mariadb.org