21
21
#include <drizzled/abort_exception.h>
22
22
#include <drizzled/error.h>
23
23
#include <drizzled/nested_join.h>
24
#include <drizzled/query_id.h>
25
24
#include <drizzled/transaction_services.h>
26
25
#include <drizzled/sql_parse.h>
27
26
#include <drizzled/data_home.h>
40
39
#include <drizzled/statement.h>
41
40
#include <drizzled/statement/alter_table.h>
42
41
#include <drizzled/probes.h>
43
#include <drizzled/global_charset_info.h>
42
#include <drizzled/charset.h>
44
43
#include <drizzled/plugin/logging.h>
45
44
#include <drizzled/plugin/query_rewrite.h>
46
45
#include <drizzled/plugin/query_cache.h>
53
52
#include <drizzled/kill.h>
54
53
#include <drizzled/schema.h>
55
54
#include <drizzled/item/subselect.h>
55
#include <drizzled/diagnostics_area.h>
56
#include <drizzled/table_ident.h>
57
#include <drizzled/statistics_variables.h>
58
#include <drizzled/system_variables.h>
59
#include <drizzled/session/times.h>
60
#include <drizzled/session/transactions.h>
61
#include <drizzled/create_field.h>
62
#include <drizzled/lex_input_stream.h>
57
64
#include <limits.h>
66
73
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
72
78
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
73
79
static bool parse_sql(Session *session, Lex_input_stream *lip);
74
void parse(Session *session, const char *inBuf, uint32_t length);
80
void parse(Session&, const char *inBuf, uint32_t length);
77
83
@defgroup Runtime_Environment Runtime Environment
81
87
extern size_t my_thread_stack_size;
82
extern const CHARSET_INFO *character_set_filesystem;
88
extern const charset_info_st *character_set_filesystem;
90
static atomic<uint64_t> g_query_id;
87
static const std::string command_name[COM_END+1]={
96
"Error" // Last command number
94
static const std::string command_name[]=
104
"Error" // Last command number
101
const char *xa_state_names[]={
108
const char *xa_state_names[]=
102
110
"NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
106
115
Mark all commands that somehow changes a table.
124
133
void init_update_queries(void)
128
for (x= 0; x <= SQLCOM_END; x++)
135
for (uint32_t x= uint32_t(SQLCOM_SELECT);
136
x <= uint32_t(SQLCOM_END); x++)
129
138
sql_command_flags[x].reset();
131
141
sql_command_flags[SQLCOM_CREATE_TABLE]= CF_CHANGES_DATA;
132
142
sql_command_flags[SQLCOM_CREATE_INDEX]= CF_CHANGES_DATA;
180
190
COM_QUIT/COM_SHUTDOWN
182
192
bool dispatch_command(enum_server_command command, Session *session,
183
char* packet, uint32_t packet_length)
193
const char* packet, uint32_t packet_length)
186
Query_id &query_id= Query_id::get_query_id();
188
197
DRIZZLE_COMMAND_START(session->thread_id, command);
190
199
session->command= command;
191
200
session->lex().sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
193
session->setQueryId(query_id.value());
201
session->times.set_time();
202
session->setQueryId(g_query_id.increment());
196
/* Ignore these statements. */
199
/* Increase id and count all other statements. */
204
if (command != COM_PING)
206
// Increase id and count all other statements
201
207
session->status_var.questions++;
205
210
/* @todo set session->lex().sql_command to SQLCOM_END here */
210
215
// We should do something about an error...
213
session->server_status&=
214
~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
218
session->server_status&= ~(SERVER_QUERY_NO_INDEX_USED | SERVER_QUERY_NO_GOOD_INDEX_USED);
219
if (packet_length == 0)
221
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
224
if (packet_length == 0)
226
my_message(ER_NO_DB_ERROR, ER(ER_NO_DB_ERROR), MYF(0));
229
if (not schema::change(*session, identifier::Schema(string(packet, packet_length))))
225
string tmp(packet, packet_length);
227
identifier::Schema identifier(tmp);
229
if (not schema::change(*session, identifier))
237
if (not session->readAndStoreQuery(packet, packet_length))
238
break; // fatal error is set
239
DRIZZLE_QUERY_START(session->getQueryString()->c_str(),
241
const_cast<const char *>(session->schema()->c_str()));
243
parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
238
session->readAndStoreQuery(packet, packet_length);
239
DRIZZLE_QUERY_START(session->getQueryString()->c_str(), session->thread_id, session->schema()->c_str());
240
parse(*session, session->getQueryString()->c_str(), session->getQueryString()->length());
248
245
/* We don't calculate statistics for this command */
249
session->main_da.disable_status(); // Don't send anything back
246
session->main_da().disable_status(); // Don't send anything back
250
247
error= true; // End server
254
252
if (packet_length != 4)
267
265
session->my_ok();
270
269
case COM_SHUTDOWN:
272
session->status_var.com_other++;
274
session->close_thread_tables(); // Free before kill
271
session->status_var.com_other++;
273
session->close_thread_tables(); // Free before kill
280
280
session->status_var.com_other++;
281
281
session->my_ok(); // Tell client we are alive
284
285
case COM_CONNECT: // Impossible here
291
292
/* If commit fails, we should be able to reset the OK status. */
292
session->main_da.can_overwrite_status= true;
293
TransactionServices &transaction_services= TransactionServices::singleton();
294
transaction_services.autocommitOrRollback(*session, session->is_error());
295
session->main_da.can_overwrite_status= false;
293
session->main_da().can_overwrite_status= true;
294
TransactionServices::autocommitOrRollback(*session, session->is_error());
295
session->main_da().can_overwrite_status= false;
297
297
session->transaction.stmt.reset();
312
312
/* Can not be true, but do not take chances in production. */
313
assert(! session->main_da.is_sent);
313
assert(! session->main_da().is_sent);
315
switch (session->main_da.status())
315
switch (session->main_da().status())
317
317
case Diagnostics_area::DA_ERROR:
318
318
/* The query failed, send error to log and abort bootstrap. */
319
session->getClient()->sendError(session->main_da.sql_errno(),
320
session->main_da.message());
319
session->getClient()->sendError(session->main_da().sql_errno(),
320
session->main_da().message());
323
323
case Diagnostics_area::DA_EOF:
395
395
1 out of memory or SHOW commands are not allowed
396
396
in this version of the server.
398
static bool _schema_select(Session *session, Select_Lex *sel,
399
const string& schema_table_name)
398
static bool _schema_select(Session& session, Select_Lex& sel, const string& schema_table_name)
401
LEX_STRING db, table;
400
lex_string_t db, table;
402
401
bitset<NUM_OF_TABLE_OPTIONS> table_options;
404
403
We have to make non const db_name & table_name
405
404
because of lower_case_table_names
407
session->make_lex_string(&db, "data_dictionary", sizeof("data_dictionary"), false);
408
session->make_lex_string(&table, schema_table_name, false);
410
if (! sel->add_table_to_list(session, new Table_ident(db, table),
411
NULL, table_options, TL_READ))
406
session.make_lex_string(&db, str_ref("data_dictionary"));
407
session.make_lex_string(&table, schema_table_name);
408
return not sel.add_table_to_list(&session, new Table_ident(db, table), NULL, table_options, TL_READ);
418
int prepare_new_schema_table(Session *session, LEX& lex,
419
const string& schema_table_name)
411
int prepare_new_schema_table(Session *session, LEX& lex0, const string& schema_table_name)
421
Select_Lex *schema_select_lex= NULL;
423
Select_Lex *select_lex= lex.current_select;
425
if (_schema_select(session, select_lex, schema_table_name))
429
TableList *table_list= (TableList*) select_lex->table_list.first;
431
table_list->schema_select_lex= schema_select_lex;
413
Select_Lex& lex= *lex0.current_select;
414
if (_schema_select(*session, lex, schema_table_name))
416
TableList *table_list= (TableList*)lex.table_list.first;
417
table_list->schema_select_lex= NULL;
491
471
session->lex().first_lists_tables_same();
473
/* list of all tables in query */
493
474
/* should be assigned after making first tables same */
494
all_tables= session->lex().query_tables;
475
TableList* all_tables= session->lex().query_tables;
496
477
/* set context for commands which do not use setup_tables */
497
478
select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
506
487
if (all_tables || ! session->lex().is_single_level_stmt())
508
drizzle_reset_errors(session, 0);
489
drizzle_reset_errors(*session, 0);
511
assert(session->transaction.stmt.hasModifiedNonTransData() == false);
492
assert(not session->transaction.stmt.hasModifiedNonTransData());
513
if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
514
&& ! session->inTransaction()
494
if (not (session->server_status & SERVER_STATUS_AUTOCOMMIT)
495
&& not session->inTransaction()
515
496
&& session->lex().statement->isTransactional())
517
if (session->startTransaction() == false)
498
if (not session->startTransaction())
519
500
my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
530
511
wants. We also keep the last value in case of SQLCOM_CALL or
533
if (! (sql_command_flags[session->lex().sql_command].test(CF_BIT_HAS_ROW_COUNT)))
514
if (not sql_command_flags[session->lex().sql_command].test(CF_BIT_HAS_ROW_COUNT))
535
516
session->row_count_func= -1;
538
return (res || session->is_error());
519
return res || session->is_error();
540
522
bool execute_sqlcom_select(Session *session, TableList *all_tables)
542
524
LEX *lex= &session->lex();
572
554
to prepend EXPLAIN to any query and receive output for it,
573
555
even if the query itself redirects the output.
575
if (!(result= new select_send()))
557
result= new select_send();
577
558
session->send_explain_fields(result);
578
559
optimizer::ExplainPlan planner;
579
560
res= planner.explainUnion(session, &session->lex().unit, result);
664
new_select(LEX *lex, bool move_down)
644
bool new_select(LEX *lex, bool move_down)
666
Select_Lex *select_lex;
667
Session *session= lex->session;
669
if (!(select_lex= new (session->mem_root) Select_Lex()))
646
Session* session= lex->session;
647
Select_Lex* select_lex= new (session->mem_root) Select_Lex;
672
649
select_lex->select_number= ++session->select_number;
673
650
select_lex->parent_lex= lex; /* Used in init_query. */
678
655
if (lex->nest_level > (int) MAX_SELECT_NESTING)
680
657
my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
684
661
select_lex->nest_level= lex->nest_level;
687
Select_Lex_Unit *unit;
688
664
/* first select_lex of subselect or derived table */
689
if (!(unit= new (session->mem_root) Select_Lex_Unit()))
665
Select_Lex_Unit* unit= new (session->mem_root) Select_Lex_Unit();
692
667
unit->init_query();
693
668
unit->init_select();
746
720
void create_select_for_variable(Session *session, const char *var_name)
749
LEX_STRING tmp, null_lex_string;
751
char buff[MAX_SYS_VAR_LENGTH*2+4+8];
754
lex= &session->lex();
756
lex->sql_command= SQLCOM_SELECT;
757
tmp.str= (char*) var_name;
758
tmp.length=strlen(var_name);
759
memset(&null_lex_string.str, 0, sizeof(null_lex_string));
722
LEX& lex= session->lex();
724
lex.sql_command= SQLCOM_SELECT;
726
tmp.assign(var_name, strlen(var_name));
761
728
We set the name of Item to @@session.var_name because that then is used
762
729
as the column name in the output.
764
if ((var= get_system_var(session, OPT_SESSION, tmp, null_lex_string)))
731
if (Item* var= get_system_var(session, OPT_SESSION, tmp, null_lex_string()))
733
char buff[MAX_SYS_VAR_LENGTH*2+4+8];
766
735
end+= snprintf(buff, sizeof(buff), "@@session.%s", var_name);
767
var->set_name(buff, end-buff, system_charset_info);
736
var->set_name(buff, end-buff);
768
737
session->add_item_to_list(var);
778
747
@param length Length of the query text
781
void parse(Session *session, const char *inBuf, uint32_t length)
750
void parse(Session& session, const char *inBuf, uint32_t length)
783
session->lex().start(session);
785
session->reset_for_next_command();
752
session.lex().start(&session);
753
session.reset_for_next_command();
786
754
/* Check if the Query is Cached if and return true if yes
787
755
* TODO the plugin has to make sure that the query is cacheble
788
756
* by setting the query_safe_cache param to TRUE
791
if (plugin::QueryCache::isCached(session))
793
res= plugin::QueryCache::sendCachedResultset(session);
758
if (plugin::QueryCache::isCached(&session) && not plugin::QueryCache::sendCachedResultset(&session))
799
LEX *lex= &session->lex();
800
Lex_input_stream lip(session, inBuf, length);
801
bool err= parse_sql(session, &lip);
805
if (not session->is_error())
807
DRIZZLE_QUERY_EXEC_START(session->getQueryString()->c_str(),
809
const_cast<const char *>(session->schema()->c_str()));
810
// Implement Views here --Brian
811
/* Actually execute the query */
814
execute_command(session);
818
// Just try to catch any random failures that could have come
822
DRIZZLE_QUERY_EXEC_DONE(0);
828
assert(session->is_error());
831
session->set_proc_info("freeing items");
832
session->end_statement();
833
session->cleanup_after_query();
834
session->set_end_timer();
760
Lex_input_stream lip(&session, inBuf, length);
761
if (parse_sql(&session, &lip))
762
assert(session.is_error());
763
else if (not session.is_error())
765
DRIZZLE_QUERY_EXEC_START(session.getQueryString()->c_str(), session.thread_id, session.schema()->c_str());
766
// Implement Views here --Brian
767
/* Actually execute the query */
770
execute_command(&session);
774
// Just try to catch any random failures that could have come
778
DRIZZLE_QUERY_EXEC_DONE(0);
780
session.lex().unit.cleanup();
781
session.set_proc_info("freeing items");
782
session.end_statement();
783
session.cleanup_after_query();
784
session.times.set_end_timer(session);
840
789
Store field definition for create.
846
bool add_field_to_list(Session *session, LEX_STRING *field_name, enum_field_types type,
847
char *length, char *decimals,
848
uint32_t type_modifier,
849
enum column_format_type column_format,
850
Item *default_value, Item *on_update_value,
853
List<String> *interval_list, const CHARSET_INFO * const cs)
795
bool add_field_to_list(Session *session, str_ref field_name, enum_field_types type,
796
const char *length, const char *decimals,
797
uint32_t type_modifier, column_format_type column_format,
798
Item *default_value, Item *on_update_value, str_ref comment,
799
const char *change, List<String> *interval_list, const charset_info_st* cs)
855
register CreateField *new_field;
856
801
LEX *lex= &session->lex();
857
802
statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
862
807
if (type_modifier & PRI_KEY_FLAG)
865
lex->col_list.push_back(new Key_part_spec(*field_name, 0));
866
key= new Key(Key::PRIMARY, null_lex_str,
867
&default_key_create_info,
869
statement->alter_info.key_list.push_back(key);
809
lex->col_list.push_back(new Key_part_spec(field_name, 0));
810
statement->alter_info.key_list.push_back(new Key(Key::PRIMARY, null_lex_string(), &default_key_create_info, 0, lex->col_list));
870
811
lex->col_list.clear();
872
813
if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG))
875
lex->col_list.push_back(new Key_part_spec(*field_name, 0));
876
key= new Key(Key::UNIQUE, null_lex_str,
877
&default_key_create_info, 0,
879
statement->alter_info.key_list.push_back(key);
815
lex->col_list.push_back(new Key_part_spec(field_name, 0));
816
statement->alter_info.key_list.push_back(new Key(Key::UNIQUE, null_lex_string(), &default_key_create_info, 0, lex->col_list));
880
817
lex->col_list.clear();
893
830
!(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
894
831
(type == DRIZZLE_TYPE_TIMESTAMP or type == DRIZZLE_TYPE_MICROTIME)))
896
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
833
my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
899
836
else if (default_value->type() == Item::NULL_ITEM)
901
838
default_value= 0;
902
839
if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG)
904
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
841
my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
908
845
else if (type_modifier & AUTO_INCREMENT_FLAG)
910
my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
847
my_error(ER_INVALID_DEFAULT, MYF(0), field_name.data());
915
852
if (on_update_value && (type != DRIZZLE_TYPE_TIMESTAMP and type != DRIZZLE_TYPE_MICROTIME))
917
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
854
my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name.data());
921
if (!(new_field= new CreateField()) ||
922
new_field->init(session, field_name->str, type, length, decimals, type_modifier,
923
default_value, on_update_value, comment, change,
924
interval_list, cs, 0, column_format))
858
CreateField* new_field= new CreateField;
859
if (new_field->init(session, field_name.data(), type, length, decimals, type_modifier, comment, change, interval_list, cs, 0, column_format)
860
|| new_field->setDefaultValue(default_value, on_update_value))
927
863
statement->alter_info.create_list.push_back(new_field);
953
889
TableList *Select_Lex::add_table_to_list(Session *session,
954
890
Table_ident *table,
956
892
const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
957
893
thr_lock_type lock_type,
958
894
List<Index_hint> *index_hints_arg,
895
lex_string_t *option)
962
897
TableList *previous_table_ref; /* The table preceding the current one. */
964
898
LEX *lex= &session->lex();
967
901
return NULL; // End of memory
968
alias_str= alias ? alias->str : table->table.str;
969
if (! table_options.test(TL_OPTION_ALIAS) &&
970
check_table_name(table->table.str, table->table.length))
902
const char* alias_str= alias ? alias->data() : table->table.data();
903
if (not table_options.test(TL_OPTION_ALIAS) && check_table_name(table->table))
972
my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
905
my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.data());
976
if (table->is_derived_table() == false && table->db.str)
909
if (not table->is_derived_table() && table->db.data())
978
my_casedn_str(files_charset_info, table->db.str);
980
identifier::Schema schema_identifier(string(table->db.str));
981
if (not schema::check(*session, schema_identifier))
911
files_charset_info->casedn_str(table->db.str_);
912
if (not schema::check(*session, identifier::Schema(table->db)))
984
my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
914
my_error(ER_WRONG_DB_NAME, MYF(0), table->db.data());
993
my_message(ER_DERIVED_MUST_HAVE_ALIAS,
994
ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
923
my_message(ER_DERIVED_MUST_HAVE_ALIAS, ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
997
if (!(alias_str= (char*) session->getMemRoot()->duplicate(alias_str,table->table.length+1)))
926
alias_str= (char*) session->mem.memdup(alias_str, table->table.size() + 1);
1000
if (!(ptr = (TableList *) session->calloc(sizeof(TableList))))
928
TableList *ptr = (TableList *) session->mem.calloc(sizeof(TableList));
930
if (table->db.data())
1005
932
ptr->setIsFqtn(true);
1006
ptr->setSchemaName(table->db.str);
1007
ptr->db_length= table->db.length;
933
ptr->setSchemaName(table->db.data());
1009
else if (lex->copy_db_to(ptr->getSchemaNamePtr(), &ptr->db_length))
937
str_ref schema = lex->session->copy_db_to();
1012
940
ptr->setIsFqtn(false);
941
ptr->setSchemaName(schema.data());
1014
944
ptr->alias= alias_str;
1015
945
ptr->setIsAlias(alias ? true : false);
1016
ptr->setTableName(table->table.str);
1017
ptr->table_name_length=table->table.length;
946
ptr->setTableName(table->table.data());
1018
947
ptr->lock_type= lock_type;
1019
948
ptr->force_index= table_options.test(TL_OPTION_FORCE_INDEX);
1020
949
ptr->ignore_leaves= table_options.test(TL_OPTION_IGNORE_LEAVES);
1021
950
ptr->derived= table->sel;
1022
951
ptr->select_lex= lex->current_select;
1023
952
ptr->index_hints= index_hints_arg;
1024
ptr->option= option ? option->str : 0;
953
ptr->option= option ? option->data() : NULL;
1025
954
/* check that used name is unique */
1026
955
if (lock_type != TL_IGNORE)
1028
957
TableList *first_table= (TableList*) table_list.first;
1029
for (TableList *tables= first_table ;
1031
tables=tables->next_local)
958
for (TableList *tables= first_table; tables; tables= tables->next_local)
1033
if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
1034
not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
960
if (not table_alias_charset->strcasecmp(alias_str, tables->alias) &&
961
not system_charset_info->strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
1036
my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
963
my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
1095
bool Select_Lex::init_nested_join(Session *session)
1020
void Select_Lex::init_nested_join(Session& session)
1098
NestedJoin *nested_join;
1100
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1101
sizeof(NestedJoin))))
1022
TableList* ptr= (TableList*) session.mem.calloc(ALIGN_SIZE(sizeof(TableList)) + sizeof(NestedJoin));
1103
1023
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1104
nested_join= ptr->getNestedJoin();
1024
NestedJoin* nested_join= ptr->getNestedJoin();
1105
1025
join_list->push_front(ptr);
1106
1026
ptr->setEmbedding(embedding);
1107
1027
ptr->setJoinList(join_list);
1130
TableList *Select_Lex::end_nested_join(Session *)
1049
TableList *Select_Lex::end_nested_join()
1133
NestedJoin *nested_join;
1135
1051
assert(embedding);
1052
TableList* ptr= embedding;
1137
1053
join_list= ptr->getJoinList();
1138
1054
embedding= ptr->getEmbedding();
1139
nested_join= ptr->getNestedJoin();
1055
NestedJoin* nested_join= ptr->getNestedJoin();
1140
1056
if (nested_join->join_list.size() == 1)
1142
1058
TableList *embedded= &nested_join->join_list.front();
1171
1087
TableList *Select_Lex::nest_last_join(Session *session)
1174
NestedJoin *nested_join;
1175
List<TableList> *embedded_list;
1177
if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1178
sizeof(NestedJoin))))
1089
TableList* ptr= (TableList*) session->mem.calloc(ALIGN_SIZE(sizeof(TableList)) + sizeof(NestedJoin));
1180
1090
ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1181
nested_join= ptr->getNestedJoin();
1091
NestedJoin* nested_join= ptr->getNestedJoin();
1182
1092
ptr->setEmbedding(embedding);
1183
1093
ptr->setJoinList(join_list);
1184
1094
ptr->alias= (char*) "(nest_last_join)";
1185
embedded_list= &nested_join->join_list;
1095
List<TableList>* embedded_list= &nested_join->join_list;
1186
1096
embedded_list->clear();
1188
1098
for (uint32_t i=0; i < 2; i++)
1326
1234
Select_Lex *first_sl= first_select();
1327
1235
assert(!fake_select_lex);
1329
if (!(fake_select_lex= new (session_arg->mem_root) Select_Lex()))
1331
fake_select_lex->include_standalone(this,
1332
(Select_Lex_Node**)&fake_select_lex);
1237
fake_select_lex= new (session_arg->mem_root) Select_Lex();
1238
fake_select_lex->include_standalone(this, (Select_Lex_Node**)&fake_select_lex);
1333
1239
fake_select_lex->select_number= INT_MAX;
1334
1240
fake_select_lex->parent_lex= &session_arg->lex(); /* Used in init_query. */
1335
1241
fake_select_lex->make_empty_select();
1377
1283
true if a memory allocation error occured
1381
push_new_name_resolution_context(Session *session,
1382
TableList *left_op, TableList *right_op)
1286
void push_new_name_resolution_context(Session& session, TableList& left_op, TableList& right_op)
1384
Name_resolution_context *on_context;
1385
if (!(on_context= new (session->mem_root) Name_resolution_context))
1288
Name_resolution_context *on_context= new (session.mem_root) Name_resolution_context;
1387
1289
on_context->init();
1388
on_context->first_name_resolution_table=
1389
left_op->first_leaf_for_name_resolution();
1390
on_context->last_name_resolution_table=
1391
right_op->last_leaf_for_name_resolution();
1392
return session->lex().push_context(on_context);
1290
on_context->first_name_resolution_table= left_op.first_leaf_for_name_resolution();
1291
on_context->last_name_resolution_table= right_op.last_leaf_for_name_resolution();
1292
session.lex().push_context(on_context);
1643
bool check_string_char_length(LEX_STRING *str, const char *err_msg,
1644
uint32_t max_char_length, const CHARSET_INFO * const cs,
1543
bool check_string_char_length(str_ref str, const char *err_msg,
1544
uint32_t max_char_length, const charset_info_st * const cs,
1647
1547
int well_formed_error;
1648
uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
1649
max_char_length, &well_formed_error);
1548
uint32_t res= cs->cset->well_formed_len(*cs, str, max_char_length, &well_formed_error);
1651
if (!well_formed_error && str->length == res)
1550
if (!well_formed_error && str.size() == res)
1655
my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_char_length);
1554
my_error(ER_WRONG_STRING_LENGTH, MYF(0), str.data(), err_msg, max_char_length);
1660
bool check_identifier_name(LEX_STRING *str, error_t err_code,
1661
uint32_t max_char_length,
1662
const char *param_for_err_msg)
1559
bool check_identifier_name(str_ref str, error_t err_code)
1561
uint32_t max_char_length= NAME_CHAR_LEN;
1665
1563
We don't support non-BMP characters in identifiers at the moment,
1666
1564
so they should be prohibited until such support is done.
1667
1565
This is why we use the 3-byte utf8 to check well-formedness here.
1669
const CHARSET_INFO * const cs= &my_charset_utf8mb4_general_ci;
1567
const charset_info_st * const cs= &my_charset_utf8mb4_general_ci;
1671
1569
int well_formed_error;
1672
uint32_t res= cs->cset->well_formed_len(cs, str->str, str->str + str->length,
1673
max_char_length, &well_formed_error);
1570
uint32_t res= cs->cset->well_formed_len(*cs, str, max_char_length, &well_formed_error);
1675
1572
if (well_formed_error)
1677
my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", str->str);
1574
my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", str.data());
1681
if (str->length == res)
1578
if (str.size() == res)
1684
1581
switch (err_code)
1688
1585
case ER_WRONG_STRING_LENGTH:
1689
my_error(err_code, MYF(0), str->str, param_for_err_msg, max_char_length);
1586
my_error(err_code, MYF(0), str.data(), "", max_char_length);
1691
1588
case ER_TOO_LONG_IDENT:
1692
my_error(err_code, MYF(0), str->str);
1589
my_error(err_code, MYF(0), str.data());