summaryrefslogtreecommitdiff
path: root/sql/sql_lex.cc
diff options
context:
space:
mode:
authorIgor Babaev <igor@askmonty.org>2022-12-23 20:54:01 -0800
committerIgor Babaev <igor@askmonty.org>2022-12-23 20:54:01 -0800
commitcea5cdd0eb30444467420f91da10752cbe697d23 (patch)
tree07a7e87441d5e55d52cf6fcb4ba918c3a04a6c65 /sql/sql_lex.cc
parenta09612014a827dc3bc09ab50bbb1b6b0b930190e (diff)
downloadmariadb-git-bb-10.11-MDEV-29971.tar.gz
MDEV-29971 Re-design the upper level of handling SELECT statementsbb-10.11-MDEV-29971
The initial patch. All tests from the main test suite passed.
Diffstat (limited to 'sql/sql_lex.cc')
-rw-r--r--sql/sql_lex.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc
index 7191465f823..bd6c9edafe9 100644
--- a/sql/sql_lex.cc
+++ b/sql/sql_lex.cc
@@ -42,6 +42,8 @@
#endif
#include "sql_update.h" // class Sql_cmd_update
#include "sql_delete.h" // class Sql_cmd_delete
+#include "sql_insert.h" // class Sql_cmd_insert
+
void LEX::parse_error(uint err_number)
{
@@ -10352,13 +10354,19 @@ SELECT_LEX *LEX::parsed_subselect(SELECT_LEX_UNIT *unit)
bool LEX::parsed_insert_select(SELECT_LEX *first_select)
{
+ bool is_insert_or_replace= false;
+ bool is_replace= false;
if (sql_command == SQLCOM_INSERT ||
sql_command == SQLCOM_REPLACE)
{
+ is_insert_or_replace= true;
if (sql_command == SQLCOM_INSERT)
sql_command= SQLCOM_INSERT_SELECT;
else
+ {
+ is_replace= true;
sql_command= SQLCOM_REPLACE_SELECT;
+ }
}
insert_select_hack(first_select);
if (check_main_unit_semantics())
@@ -10368,6 +10376,23 @@ bool LEX::parsed_insert_select(SELECT_LEX *first_select)
SELECT_LEX *blt __attribute__((unused))= pop_select();
DBUG_ASSERT(blt == &builtin_select);
push_select(first_select);
+
+ if (is_insert_or_replace)
+ {
+ if (sql_command == SQLCOM_INSERT || sql_command == SQLCOM_REPLACE)
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_values(is_replace,
+ duplicates)))
+ return true;
+ }
+ else
+ {
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_insert_select(is_replace,
+ duplicates)))
+ return true;
+ }
+ }
+
return false;
}
@@ -10450,6 +10475,8 @@ bool LEX::select_finalize(st_select_lex_unit *expr)
{
sql_command= SQLCOM_SELECT;
selects_allow_procedure= TRUE;
+ if (!(m_sql_cmd= new (thd->mem_root) Sql_cmd_select(result)))
+ return true;
if (set_main_unit(expr))
return true;
return check_main_unit_semantics();
@@ -11921,3 +11948,27 @@ bool SELECT_LEX_UNIT::is_derived_eliminated() const
return false;
return derived->table->map & outer_select()->join->eliminated_tables;
}
+
+bool SELECT_LEX_UNIT::executed_at_prepare_phase()
+{
+ for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select())
+ {
+ if (!sl->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}
+
+bool SELECT_LEX::executed_at_prepare_phase()
+{
+ if (table_list.elements || is_correlated)
+ return false;
+ for (st_select_lex_unit *unit= first_inner_unit();
+ unit;
+ unit= unit->next_unit())
+ {
+ if (!unit->executed_at_prepare_phase())
+ return false;
+ }
+ return true;
+}