summaryrefslogtreecommitdiff
path: root/sql/sql_window.h
diff options
context:
space:
mode:
authorSergei Petrunia <sergey@mariadb.com>2022-05-03 14:06:27 +0300
committerSergei Petrunia <sergey@mariadb.com>2022-05-04 15:47:45 +0300
commitba4927e520190bbad763bb5260ae154f29a61231 (patch)
treeb261a4a612505740e071456b649865eceaf9a252 /sql/sql_window.h
parent794bebf9ee18de4138c4d2c93853d49ff3af7f12 (diff)
downloadmariadb-git-ba4927e520190bbad763bb5260ae154f29a61231.tar.gz
MDEV-19398: Assertion `item1->type() == Item::FIELD_ITEM ...
Window Functions code tries to minimize the number of times it needs to sort the select's resultset by finding "compatible" OVER (PARTITION BY ... ORDER BY ...) clauses. This employs compare_order_elements(). That function assumed that the order expressions are Item_field-derived objects (that refer to a temp.table). But this is not always the case: one can construct queries order expressions are arbitrary item expressions. Add handling for such expressions: sort them according to the window specification they appeared in. This means we cannot detect that two compatible PARTITION BY clauses that use expressions can share the sorting step. But at least we won't crash.
Diffstat (limited to 'sql/sql_window.h')
-rw-r--r--sql/sql_window.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/sql/sql_window.h b/sql/sql_window.h
index 417d0bca12c..b29038fc374 100644
--- a/sql/sql_window.h
+++ b/sql/sql_window.h
@@ -108,6 +108,13 @@ class Window_spec : public Sql_alloc
Window_spec *referenced_win_spec;
+ /*
+ Window_spec objects are numbered by the number of their appearance in the
+ query. This is used by compare_order_elements() to provide a predictable
+ ordering of PARTITION/ORDER BY clauses.
+ */
+ int win_spec_number;
+
Window_spec(LEX_STRING *win_ref,
SQL_I_List<ORDER> *part_list,
SQL_I_List<ORDER> *ord_list,