summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2016-09-29 01:15:00 -0700
committerIgor Babaev <igor@askmonty.org>2016-09-30 17:40:40 -0700
commit903f34c7a99d15ca1b861a7dd4848ebed9891c44 (patch)
tree80e25801f2ae4bc53bf1705c6360d8062a14c702 /sql
parent6aeaebd8cfa3ce3cf7037a282a77ca4c6cdb7e16 (diff)
downloadmariadb-git-903f34c7a99d15ca1b861a7dd4848ebed9891c44.tar.gz
Fixed bug mdev-10868.
There was no implementation of the virtual method print() for the Item_window_func class. As a result for a view containing window function an invalid view definition could be written in the frm file. When a query that refers to this view was executed a syntax error was reported.
Diffstat (limited to 'sql')
-rw-r--r--sql/item_windowfunc.cc7
-rw-r--r--sql/item_windowfunc.h4
-rw-r--r--sql/sql_window.cc78
-rw-r--r--sql/sql_window.h7
4 files changed, 95 insertions, 1 deletions
diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc
index ccdbdd3294f..a13967eaaad 100644
--- a/sql/item_windowfunc.cc
+++ b/sql/item_windowfunc.cc
@@ -446,3 +446,10 @@ void Item_sum_hybrid_simple::update_field()
{
DBUG_ASSERT(0);
}
+
+void Item_window_func::print(String *str, enum_query_type query_type)
+{
+ window_func()->print(str, query_type);
+ str->append(" over ");
+ window_spec->print(str, query_type);
+}
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
index 5b368e2cdbc..15e5c9a7c5b 100644
--- a/sql/item_windowfunc.h
+++ b/sql/item_windowfunc.h
@@ -963,7 +963,9 @@ public:
bool resolve_window_name(THD *thd);
- Item *get_copy(THD *thd, MEM_ROOT *mem_root) { return 0; }
+ void print(String *str, enum_query_type query_type);
+
+ Item *get_copy(THD *thd, MEM_ROOT *mem_root) { return 0; }
};
diff --git a/sql/sql_window.cc b/sql/sql_window.cc
index 8fed2418b82..28be70c2890 100644
--- a/sql/sql_window.cc
+++ b/sql/sql_window.cc
@@ -61,6 +61,25 @@ Window_spec::check_window_names(List_iterator_fast<Window_spec> &it)
return false;
}
+void
+Window_spec::print(String *str, enum_query_type query_type)
+{
+ str->append('(');
+ if (partition_list->first)
+ {
+ str->append(STRING_WITH_LEN(" partition by "));
+ st_select_lex::print_order(str, partition_list->first, query_type);
+ }
+ if (order_list->first)
+ {
+ str->append(STRING_WITH_LEN(" order by "));
+ st_select_lex::print_order(str, order_list->first, query_type);
+ }
+ if (window_frame)
+ window_frame->print(str, query_type);
+ str->append(')');
+}
+
bool
Window_frame::check_frame_bounds()
{
@@ -81,6 +100,65 @@ Window_frame::check_frame_bounds()
}
+void
+Window_frame::print(String *str, enum_query_type query_type)
+{
+ switch (units) {
+ case UNITS_ROWS:
+ str->append(STRING_WITH_LEN(" rows "));
+ break;
+ case UNITS_RANGE: str->append(STRING_WITH_LEN(" range "));
+ }
+
+ str->append(STRING_WITH_LEN("between "));
+ top_bound->print(str, query_type);
+ str->append(STRING_WITH_LEN(" and "));
+ bottom_bound->print(str, query_type);
+
+ if (exclusion != EXCL_NONE)
+ {
+ str->append(STRING_WITH_LEN(" exclude "));
+ switch (exclusion) {
+ case EXCL_CURRENT_ROW:
+ str->append(STRING_WITH_LEN(" current row "));
+ break;
+ case EXCL_GROUP:
+ str->append(STRING_WITH_LEN(" group "));
+ break;
+ case EXCL_TIES:
+ str->append(STRING_WITH_LEN(" ties "));
+ break;
+ default:
+ ;
+ }
+ }
+}
+
+
+void
+Window_frame_bound::print(String *str, enum_query_type query_type)
+{
+ if (precedence_type == CURRENT)
+ {
+ str->append(STRING_WITH_LEN(" current row "));
+ return;
+ }
+ if (is_unbounded())
+ str->append(STRING_WITH_LEN(" unbounded "));
+ else
+ offset->print(str ,query_type);
+ switch (precedence_type) {
+ case PRECEDING:
+ str->append(STRING_WITH_LEN(" preceding "));
+ break;
+ case FOLLOWING:
+ str->append(STRING_WITH_LEN(" following "));
+ break;
+ default:
+ DBUG_ASSERT(0);
+ }
+}
+
/*
Setup window functions in a select
*/
diff --git a/sql/sql_window.h b/sql/sql_window.h
index b94a1fc6dc4..6a56fc84392 100644
--- a/sql/sql_window.h
+++ b/sql/sql_window.h
@@ -45,6 +45,8 @@ public:
bool is_unbounded() { return offset == NULL; }
+ void print(String *str, enum_query_type query_type);
+
};
@@ -84,6 +86,8 @@ public:
bool check_frame_bounds();
+ void print(String *str, enum_query_type query_type);
+
};
class Window_spec : public Sql_alloc
@@ -125,6 +129,9 @@ class Window_spec : public Sql_alloc
{
*(partition_list->next)= NULL;
}
+
+ void print(String *str, enum_query_type query_type);
+
};
class Window_def : public Window_spec