diff options
author | Igor Babaev <igor@askmonty.org> | 2018-09-13 00:35:28 -0700 |
---|---|---|
committer | Igor Babaev <igor@askmonty.org> | 2018-09-14 18:13:16 -0700 |
commit | 3473e0452ed5edb567f49b26c9f506431e175ac4 (patch) | |
tree | dabdea5e4002d73a4ae29841973d9cad6ee8dd45 /sql/item.h | |
parent | 6b2da933592b54616467d08313fcb1d958fc67e4 (diff) | |
download | mariadb-git-3473e0452ed5edb567f49b26c9f506431e175ac4.tar.gz |
MDEV-17154 Multiple selects from parametrized CTE fails with syntax error
This patch fills a serious flaw in the implementation of common table
expressions. Before this patch an attempt to prepare a statement from
a query with a parameter marker in a CTE that was used more than once
in the query ended up with a bogus error message. Similarly if a statement
in a stored procedure contained a CTE whose specification used a
local variables and this CTE was referred to more than once in the
statement then the server failed to execute the stored procedure returning
a bogus error message on a non-existing field.
The problems appeared due to incorrect handling of parameter markers /
local variables in CTEs that were referred more than once.
This patch fixes the problems by differentiating between the original
occurrences of a parameter marker / local variable used in the
specification of a CTE and the corresponding occurrences used
in copies of this specification. These copies are substituted
instead of non-first references to the CTE.
The idea of the fix and even some code were taken from the MySQL
implementation of the common table expressions.
Diffstat (limited to 'sql/item.h')
-rw-r--r-- | sql/item.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/sql/item.h b/sql/item.h index 8fad8dadf22..1a280e3091f 100644 --- a/sql/item.h +++ b/sql/item.h @@ -28,6 +28,7 @@ #include "field.h" /* Derivation */ #include "sql_type.h" #include "sql_time.h" +#include "mem_root_array.h" C_MODE_START #include <ma_dyncol.h> @@ -3067,6 +3068,10 @@ public: bool check_vcol_func_processor(void *int_arg) {return FALSE;} Item *get_copy(THD *thd, MEM_ROOT *mem_root) { return 0; } + bool add_as_clone(THD *thd); + void sync_clones(); + bool register_clone(Item_param *i) { return m_clones.push_back(i); } + private: void invalid_default_param() const; @@ -3082,6 +3087,12 @@ public: private: Send_field *m_out_param_info; bool m_is_settable_routine_parameter; + /* + Array of all references of this parameter marker used in a CTE to its clones + created for copies of this marker used the CTE's copies. It's used to + synchronize the actual value of the parameter with the values of the clones. + */ + Mem_root_array<Item_param *, true> m_clones; }; |