summaryrefslogtreecommitdiff
path: root/sql/sql_insert.h
diff options
context:
space:
mode:
Diffstat (limited to 'sql/sql_insert.h')
-rw-r--r--sql/sql_insert.h136
1 files changed, 136 insertions, 0 deletions
diff --git a/sql/sql_insert.h b/sql/sql_insert.h
index 8b034c25877..eae3b5357bd 100644
--- a/sql/sql_insert.h
+++ b/sql/sql_insert.h
@@ -18,6 +18,7 @@
#include "sql_class.h" /* enum_duplicates */
#include "sql_list.h"
+#include "sql_base.h"
/* Instead of including sql_lex.h we add this typedef here */
typedef List<Item> List_item;
@@ -51,4 +52,139 @@ bool binlog_drop_table(THD *thd, TABLE *table);
inline void kill_delayed_threads(void) {}
#endif
+
+/**
+ Base class for all INSERT and REPLACE statements. Abstract class that
+ is inherited by Sql_cmd_insert_values and Sql_cmd_insert_select.
+*/
+
+class Sql_cmd_insert_base : public Sql_cmd_dml
+{
+protected:
+ virtual bool precheck(THD *thd) override;
+
+ virtual bool prepare_inner(THD *thd) override;
+
+private:
+ bool resolve_update_expressions(THD *thd);
+ bool prepare_values_table(THD *thd);
+ bool resolve_values_table_columns(THD *thd);
+
+ /**
+ Field list to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... (col1, ... colN) VALUES ... syntax
+ this is a list of col1, ..., colN fields.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this is a list of col1, ... colM fields as well.
+ */
+ List<Item> insert_field_list;
+
+public:
+ /*
+ field_list was created for view and should be removed before PS/SP
+ rexecuton
+ */
+ bool empty_field_list_on_rset;
+
+ DML_prelocking_strategy *get_dml_prelocking_strategy()
+ {
+ return &dml_prelocking_strategy;
+ }
+
+protected:
+ const bool is_replace;
+
+ /**
+ Row data to insert/replace
+
+ One of two things:
+ 1. For the INSERT/REPLACE ... VALUES (row1), (row2), ... (rowN) syntax
+ the list contains N List_item lists: one List_item per row.
+ 2. For the INSERT/REPLACE ... SET col1=x1, ... colM=xM syntax extension
+ this list contains only 1 List_item of M data values: this way we
+ emulate this syntax:
+ INSERT/REPLACE ... (col1, ... colM) VALUE (x1, ..., xM);
+ */
+ List<List_item> insert_many_values;
+
+ /*
+ Number of values per row in insert_many_values, available after resolving
+ */
+ uint value_count;
+
+ /* ON DUPLICATE KEY UPDATE field list */
+ List<Item> update_field_list;
+
+ const enum_duplicates duplicates;
+
+ Protocol *save_protocol; /**< needed for ANALYZE .. INSERT .. RETURNING */
+
+ explicit Sql_cmd_insert_base(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : empty_field_list_on_rset(false),
+ is_replace(is_replace_arg),
+ value_count(0),
+ duplicates(duplicates_arg),
+ save_protocol(NULL)
+ {}
+
+#if 0
+ virtual void cleanup(THD *thd) override
+ {
+ if (empty_field_list_on_rset)
+ {
+ empty_field_list_on_rset = false;
+ insert_field_list.empty();
+ }
+ }
+#endif
+
+private:
+
+ /* The prelocking strategy used when opening the used tables */
+ DML_prelocking_strategy dml_prelocking_strategy;
+
+};
+
+
+/**
+ Class that implements INSERT ... VALUES and REPLACE ... VALUES statements.
+*/
+
+class Sql_cmd_insert_values final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_values(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE : SQLCOM_INSERT;
+ }
+
+};
+
+
+/**
+ Class that implements INSERT ... SELECT and REPLACE ... SELECT statements.
+*/
+
+class Sql_cmd_insert_select final : public Sql_cmd_insert_base
+{
+public:
+ explicit Sql_cmd_insert_select(bool is_replace_arg,
+ enum_duplicates duplicates_arg)
+ : Sql_cmd_insert_base(is_replace_arg, duplicates_arg) {}
+
+ enum_sql_command sql_command_code() const
+ {
+ return is_replace ? SQLCOM_REPLACE_SELECT : SQLCOM_INSERT_SELECT;
+ }
+};
+
+
+
#endif /* SQL_INSERT_INCLUDED */