summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorunknown <sanja@askmonty.org>2011-07-21 23:37:40 +0300
committerunknown <sanja@askmonty.org>2011-07-21 23:37:40 +0300
commit813aaac51d2aaf0c582cbcd869fd48b948b90d66 (patch)
treedd0723f7e841410ec714d4e52510f807ceddf754 /sql
parentc86ffc23ee737b258dc006669ccfb3600e6f4c2e (diff)
downloadmariadb-git-813aaac51d2aaf0c582cbcd869fd48b948b90d66.tar.gz
Fix for LP BUG#806071
In case of two views with subqueries it is dificult to decide about order of injected ORDER BY clauses. A simple solution is just prohibit ORDER BY injection if there is other order by. mysql-test/r/view.result: New test added, old test changed. mysql-test/t/view.test: New test aded. sql/share/errmsg.txt: new warning added. sql/sql_view.cc: Inject ORDER BY only if there is no other one. Warning about ignoring ORDER BY in this case for EXPLAIN EXTENDED.
Diffstat (limited to 'sql')
-rw-r--r--sql/share/errmsg.txt2
-rw-r--r--sql/sql_view.cc16
2 files changed, 17 insertions, 1 deletions
diff --git a/sql/share/errmsg.txt b/sql/share/errmsg.txt
index b0989388028..928a28aba24 100644
--- a/sql/share/errmsg.txt
+++ b/sql/share/errmsg.txt
@@ -6288,3 +6288,5 @@ ER_QUERY_CACHE_IS_DISABLED
eng "Query cache is disabled (resize or similar command in progress); repeat this command later"
ER_QUERY_CACHE_IS_GLOBALY_DISABLED
eng "Query cache is globally disabled and you can't enable it only for this session"
+ER_VIEW_ORDERBY_IGNORED
+ eng "View '%-.192s'.'%-.192s' ORDER BY clause ignored because there is other ORDER BY clause already."
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 89ccfd10a45..535cc30e3e8 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -1483,8 +1483,22 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table,
We can safely ignore the VIEW's ORDER BY if we merge into union
branch, as order is not important there.
*/
- if (!table->select_lex->master_unit()->is_union())
+ if (!table->select_lex->master_unit()->is_union() &&
+ table->select_lex->order_list.elements == 0)
table->select_lex->order_list.push_back(&lex->select_lex.order_list);
+ else
+ {
+ if (old_lex->sql_command == SQLCOM_SELECT &&
+ (old_lex->describe & DESCRIBE_EXTENDED) &&
+ lex->select_lex.order_list.elements &&
+ !table->select_lex->master_unit()->is_union())
+ {
+ push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
+ ER_VIEW_ORDERBY_IGNORED,
+ ER(ER_VIEW_ORDERBY_IGNORED),
+ table->db, table->table_name);
+ }
+ }
/*
This SELECT_LEX will be linked in global SELECT_LEX list
to make it processed by mysql_handle_derived(),