← Back to team overview

maria-developers team mailing list archive

Re: 72b709a: MDEV-9701: CREATE VIEW with GROUP BY or ORDER BY and constant produces invalid definition

 

On 17.03.2016 10:21, Sergei Golubchik wrote:
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?
It worked because of IF which avoid printing order number in case of printing for VIEW (expression was printed) so not 1 but a (or even constant in the case of the bug)


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
OK

+      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.
According to the test case we have in case of integer parameter 'ORDER BY ?' interpret as "by which column we will order", so result order differs depends on execution parameter.


Regards,
Sergei
Chief Architect MariaDB
and security@xxxxxxxxxxx



References