~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Brian Aker
  • Date: 2008-10-20 03:40:03 UTC
  • mto: (492.3.21 drizzle-clean-code)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: brian@tangent.org-20081020034003-t2dcnl0ayr2ymm8k
THD -> Session rename

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
  "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
57
57
};
58
58
 
59
 
static void unlock_locked_tables(THD *thd)
 
59
static void unlock_locked_tables(Session *thd)
60
60
{
61
61
  if (thd->locked_tables)
62
62
  {
67
67
}
68
68
 
69
69
 
70
 
bool end_active_trans(THD *thd)
 
70
bool end_active_trans(Session *thd)
71
71
{
72
72
  int error= 0;
73
73
 
93
93
}
94
94
 
95
95
 
96
 
bool begin_trans(THD *thd)
 
96
bool begin_trans(Session *thd)
97
97
{
98
98
  int error= 0;
99
99
  if (thd->locked_tables)
118
118
/**
119
119
  Returns true if all tables should be ignored.
120
120
*/
121
 
inline bool all_tables_not_ok(THD *thd, TableList *tables)
 
121
inline bool all_tables_not_ok(Session *thd, TableList *tables)
122
122
{
123
123
  return rpl_filter->is_on() && tables &&
124
124
         !rpl_filter->tables_ok(thd->db, tables);
125
125
}
126
126
 
127
127
 
128
 
static bool some_non_temp_table_to_be_updated(THD *thd, TableList *tables)
 
128
static bool some_non_temp_table_to_be_updated(Session *thd, TableList *tables)
129
129
{
130
130
  for (TableList *table= tables; table; table= table->next_global)
131
131
  {
213
213
  return (sql_command_flags[command] & CF_CHANGES_DATA) != 0;
214
214
}
215
215
 
216
 
void execute_init_command(THD *thd, sys_var_str *init_command_var,
 
216
void execute_init_command(Session *thd, sys_var_str *init_command_var,
217
217
                          rw_lock_t *var_mutex)
218
218
{
219
219
  Vio* save_vio;
252
252
    0   OK
253
253
*/
254
254
 
255
 
int end_trans(THD *thd, enum enum_mysql_completiontype completion)
 
255
int end_trans(Session *thd, enum enum_mysql_completiontype completion)
256
256
{
257
257
  bool do_release= 0;
258
258
  int res= 0;
305
305
  if (res < 0)
306
306
    my_error(thd->killed_errno(), MYF(0));
307
307
  else if ((res == 0) && do_release)
308
 
    thd->killed= THD::KILL_CONNECTION;
 
308
    thd->killed= Session::KILL_CONNECTION;
309
309
 
310
310
  return(res);
311
311
}
323
323
    1  request of thread shutdown (see dispatch_command() description)
324
324
*/
325
325
 
326
 
bool do_command(THD *thd)
 
326
bool do_command(Session *thd)
327
327
{
328
328
  bool return_value;
329
329
  char *packet= 0;
422
422
    @retval false The statement isn't updating any relevant tables.
423
423
*/
424
424
 
425
 
static bool deny_updates_if_read_only_option(THD *thd,
 
425
static bool deny_updates_if_read_only_option(Session *thd,
426
426
                                                TableList *all_tables)
427
427
{
428
428
  if (!opt_readonly)
488
488
    1   request of thread shutdown, i. e. if command is
489
489
        COM_QUIT/COM_SHUTDOWN
490
490
*/
491
 
bool dispatch_command(enum enum_server_command command, THD *thd,
 
491
bool dispatch_command(enum enum_server_command command, Session *thd,
492
492
                      char* packet, uint32_t packet_length)
493
493
{
494
494
  NET *net= &thd->net;
833
833
    if (! thd->main_da.is_set())
834
834
      thd->send_kill_message();
835
835
  }
836
 
  if (thd->killed == THD::KILL_QUERY || thd->killed == THD::KILL_BAD_DATA)
 
836
  if (thd->killed == Session::KILL_QUERY || thd->killed == Session::KILL_BAD_DATA)
837
837
  {
838
 
    thd->killed= THD::NOT_KILLED;
 
838
    thd->killed= Session::NOT_KILLED;
839
839
    thd->mysys_var->abort= 0;
840
840
  }
841
841
 
861
861
}
862
862
 
863
863
 
864
 
void log_slow_statement(THD *thd)
 
864
void log_slow_statement(Session *thd)
865
865
{
866
866
  logging_post_do(thd);
867
867
 
895
895
                      in this version of the server.
896
896
*/
897
897
 
898
 
int prepare_schema_table(THD *thd, LEX *lex, Table_ident *table_ident,
 
898
int prepare_schema_table(Session *thd, LEX *lex, Table_ident *table_ident,
899
899
                         enum enum_schema_tables schema_table_idx)
900
900
{
901
901
  SELECT_LEX *schema_select_lex= NULL;
969
969
  Read query from packet and store in thd->query.
970
970
  Used in COM_QUERY and COM_STMT_PREPARE.
971
971
 
972
 
    Sets the following THD variables:
 
972
    Sets the following Session variables:
973
973
  - query
974
974
  - query_length
975
975
 
979
979
    true  error;  In this case thd->fatal_error is set
980
980
*/
981
981
 
982
 
bool alloc_query(THD *thd, const char *packet, uint32_t packet_length)
 
982
bool alloc_query(Session *thd, const char *packet, uint32_t packet_length)
983
983
{
984
984
  /* Remove garbage at start and end of query */
985
985
  while (packet_length > 0 && my_isspace(thd->charset(), packet[0]))
1010
1010
  return false;
1011
1011
}
1012
1012
 
1013
 
static void reset_one_shot_variables(THD *thd) 
 
1013
static void reset_one_shot_variables(Session *thd) 
1014
1014
{
1015
1015
  thd->variables.character_set_client=
1016
1016
    global_system_variables.character_set_client;
1059
1059
*/
1060
1060
 
1061
1061
int
1062
 
mysql_execute_command(THD *thd)
 
1062
mysql_execute_command(Session *thd)
1063
1063
{
1064
1064
  int res= false;
1065
1065
  bool need_start_waiting= false; // have protection against global read lock
2409
2409
  return(res || thd->is_error());
2410
2410
}
2411
2411
 
2412
 
bool execute_sqlcom_select(THD *thd, TableList *all_tables)
 
2412
bool execute_sqlcom_select(Session *thd, TableList *all_tables)
2413
2413
{
2414
2414
  LEX   *lex= thd->lex;
2415
2415
  select_result *result=lex->result;
2479
2479
    corresponding exec. (Thus we only have to check in fix_fields.)
2480
2480
  - Passing to check_stack_overrun() prevents the compiler from removing it.
2481
2481
*/
2482
 
bool check_stack_overrun(THD *thd, long margin,
 
2482
bool check_stack_overrun(Session *thd, long margin,
2483
2483
                         unsigned char *buf __attribute__((unused)))
2484
2484
{
2485
2485
  long stack_used;
2528
2528
 
2529
2529
 
2530
2530
/**
2531
 
 Reset THD part responsible for command processing state.
 
2531
 Reset Session part responsible for command processing state.
2532
2532
 
2533
2533
   This needs to be called before execution of every statement
2534
2534
   (prepared or conventional).
2535
2535
   It is not called by substatements of routines.
2536
2536
 
2537
2537
  @todo
2538
 
   Make it a method of THD and align its name with the rest of
 
2538
   Make it a method of Session and align its name with the rest of
2539
2539
   reset/end/start/init methods.
2540
2540
  @todo
2541
 
   Call it after we use THD for queries, not before.
 
2541
   Call it after we use Session for queries, not before.
2542
2542
*/
2543
2543
 
2544
 
void mysql_reset_thd_for_next_command(THD *thd)
 
2544
void mysql_reset_thd_for_next_command(Session *thd)
2545
2545
{
2546
2546
  thd->free_list= 0;
2547
2547
  thd->select_number= 1;
2548
2548
  /*
2549
2549
    Those two lines below are theoretically unneeded as
2550
 
    THD::cleanup_after_query() should take care of this already.
 
2550
    Session::cleanup_after_query() should take care of this already.
2551
2551
  */
2552
2552
  thd->auto_inc_intervals_in_cur_stmt_for_binlog.empty();
2553
2553
  thd->stmt_depends_on_first_successful_insert_id_in_prev_stmt= 0;
2609
2609
mysql_new_select(LEX *lex, bool move_down)
2610
2610
{
2611
2611
  SELECT_LEX *select_lex;
2612
 
  THD *thd= lex->thd;
 
2612
  Session *thd= lex->thd;
2613
2613
 
2614
2614
  if (!(select_lex= new (thd->mem_root) SELECT_LEX()))
2615
2615
    return(1);
2684
2684
 
2685
2685
void create_select_for_variable(const char *var_name)
2686
2686
{
2687
 
  THD *thd;
 
2687
  Session *thd;
2688
2688
  LEX *lex;
2689
2689
  LEX_STRING tmp, null_lex_string;
2690
2690
  Item *var;
2739
2739
                               the next query in the query text.
2740
2740
*/
2741
2741
 
2742
 
void mysql_parse(THD *thd, const char *inBuf, uint32_t length,
 
2742
void mysql_parse(Session *thd, const char *inBuf, uint32_t length,
2743
2743
                 const char ** found_semicolon)
2744
2744
{
2745
2745
  /*
2817
2817
    1   can be ignored
2818
2818
*/
2819
2819
 
2820
 
bool mysql_test_parse_for_slave(THD *thd, char *inBuf, uint32_t length)
 
2820
bool mysql_test_parse_for_slave(Session *thd, char *inBuf, uint32_t length)
2821
2821
{
2822
2822
  LEX *lex= thd->lex;
2823
2823
  bool error= 0;
2843
2843
    Return 0 if ok
2844
2844
*/
2845
2845
 
2846
 
bool add_field_to_list(THD *thd, LEX_STRING *field_name, enum_field_types type,
 
2846
bool add_field_to_list(Session *thd, LEX_STRING *field_name, enum_field_types type,
2847
2847
                       char *length, char *decimals,
2848
2848
                       uint32_t type_modifier,
2849
2849
                       enum column_format_type column_format,
2940
2940
}
2941
2941
 
2942
2942
bool
2943
 
add_proc_to_list(THD* thd, Item *item)
 
2943
add_proc_to_list(Session* thd, Item *item)
2944
2944
{
2945
2945
  order_st *order;
2946
2946
  Item  **item_ptr;
2960
2960
  save order by and tables in own lists.
2961
2961
*/
2962
2962
 
2963
 
bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
 
2963
bool add_to_list(Session *thd, SQL_LIST &list,Item *item,bool asc)
2964
2964
{
2965
2965
  order_st *order;
2966
2966
  if (!(order = (order_st *) thd->alloc(sizeof(order_st))))
2995
2995
    \#  Pointer to TableList element added to the total table list
2996
2996
*/
2997
2997
 
2998
 
TableList *st_select_lex::add_table_to_list(THD *thd,
 
2998
TableList *st_select_lex::add_table_to_list(Session *thd,
2999
2999
                                             Table_ident *table,
3000
3000
                                             LEX_STRING *alias,
3001
3001
                                             uint32_t table_options,
3156
3156
    1   otherwise
3157
3157
*/
3158
3158
 
3159
 
bool st_select_lex::init_nested_join(THD *thd)
 
3159
bool st_select_lex::init_nested_join(Session *thd)
3160
3160
{
3161
3161
  TableList *ptr;
3162
3162
  nested_join_st *nested_join;
3192
3192
    - 0, otherwise
3193
3193
*/
3194
3194
 
3195
 
TableList *st_select_lex::end_nested_join(THD *thd __attribute__((unused)))
 
3195
TableList *st_select_lex::end_nested_join(Session *thd __attribute__((unused)))
3196
3196
{
3197
3197
  TableList *ptr;
3198
3198
  nested_join_st *nested_join;
3233
3233
    \#  Pointer to TableList element created for the new nested join
3234
3234
*/
3235
3235
 
3236
 
TableList *st_select_lex::nest_last_join(THD *thd)
 
3236
TableList *st_select_lex::nest_last_join(Session *thd)
3237
3237
{
3238
3238
  TableList *ptr;
3239
3239
  nested_join_st *nested_join;
3392
3392
    0     on success
3393
3393
*/
3394
3394
 
3395
 
bool st_select_lex_unit::add_fake_select_lex(THD *thd_arg)
 
3395
bool st_select_lex_unit::add_fake_select_lex(Session *thd_arg)
3396
3396
{
3397
3397
  SELECT_LEX *first_sl= first_select();
3398
3398
  assert(!fake_select_lex);
3449
3449
*/
3450
3450
 
3451
3451
bool
3452
 
push_new_name_resolution_context(THD *thd,
 
3452
push_new_name_resolution_context(Session *thd,
3453
3453
                                 TableList *left_op, TableList *right_op)
3454
3454
{
3455
3455
  Name_resolution_context *on_context;
3558
3558
    @retval !=0  Error; thd->killed is set or thd->is_error() is true
3559
3559
*/
3560
3560
 
3561
 
bool reload_cache(THD *thd, ulong options, TableList *tables,
 
3561
bool reload_cache(Session *thd, ulong options, TableList *tables,
3562
3562
                          bool *write_to_binlog)
3563
3563
{
3564
3564
  bool result=0;
3682
3682
*/
3683
3683
 
3684
3684
static unsigned int
3685
 
kill_one_thread(THD *thd __attribute__((unused)),
 
3685
kill_one_thread(Session *thd __attribute__((unused)),
3686
3686
                ulong id, bool only_kill_query)
3687
3687
{
3688
 
  THD *tmp;
 
3688
  Session *tmp;
3689
3689
  uint32_t error=ER_NO_SUCH_THREAD;
3690
3690
  pthread_mutex_lock(&LOCK_thread_count); // For unlink from list
3691
 
  I_List_iterator<THD> it(threads);
 
3691
  I_List_iterator<Session> it(threads);
3692
3692
  while ((tmp=it++))
3693
3693
  {
3694
3694
    if (tmp->command == COM_DAEMON)
3702
3702
  pthread_mutex_unlock(&LOCK_thread_count);
3703
3703
  if (tmp)
3704
3704
  {
3705
 
    tmp->awake(only_kill_query ? THD::KILL_QUERY : THD::KILL_CONNECTION);
 
3705
    tmp->awake(only_kill_query ? Session::KILL_QUERY : Session::KILL_CONNECTION);
3706
3706
    error=0;
3707
3707
    pthread_mutex_unlock(&tmp->LOCK_delete);
3708
3708
  }
3720
3720
    only_kill_query     Should it kill the query or the connection
3721
3721
*/
3722
3722
 
3723
 
void sql_kill(THD *thd, ulong id, bool only_kill_query)
 
3723
void sql_kill(Session *thd, ulong id, bool only_kill_query)
3724
3724
{
3725
3725
  uint32_t error;
3726
3726
  if (!(error= kill_one_thread(thd, id, only_kill_query)))
3732
3732
 
3733
3733
/** If pointer is not a null pointer, append filename to it. */
3734
3734
 
3735
 
bool append_file_to_dir(THD *thd, const char **filename_ptr,
 
3735
bool append_file_to_dir(Session *thd, const char **filename_ptr,
3736
3736
                        const char *table_name)
3737
3737
{
3738
3738
  char buff[FN_REFLEN],*ptr, *end;
3768
3768
 
3769
3769
bool check_simple_select()
3770
3770
{
3771
 
  THD *thd= current_thd;
 
3771
  Session *thd= current_thd;
3772
3772
  LEX *lex= thd->lex;
3773
3773
  if (lex->current_select != &lex->select_lex)
3774
3774
  {
3862
3862
    true  Error
3863
3863
*/
3864
3864
 
3865
 
bool multi_update_precheck(THD *thd,
 
3865
bool multi_update_precheck(Session *thd,
3866
3866
                           TableList *tables __attribute__((unused)))
3867
3867
{
3868
3868
  const char *msg= 0;
3899
3899
    true  error
3900
3900
*/
3901
3901
 
3902
 
bool multi_delete_precheck(THD *thd,
 
3902
bool multi_delete_precheck(Session *thd,
3903
3903
                           TableList *tables __attribute__((unused)))
3904
3904
{
3905
3905
  SELECT_LEX *select_lex= &thd->lex->select_lex;
4027
4027
    true  Error
4028
4028
*/
4029
4029
 
4030
 
bool update_precheck(THD *thd, TableList *tables __attribute__((unused)))
 
4030
bool update_precheck(Session *thd, TableList *tables __attribute__((unused)))
4031
4031
{
4032
4032
  if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
4033
4033
  {
4050
4050
    true   error
4051
4051
*/
4052
4052
 
4053
 
bool insert_precheck(THD *thd, TableList *tables __attribute__((unused)))
 
4053
bool insert_precheck(Session *thd, TableList *tables __attribute__((unused)))
4054
4054
{
4055
4055
  LEX *lex= thd->lex;
4056
4056
 
4080
4080
    true   Error
4081
4081
*/
4082
4082
 
4083
 
bool create_table_precheck(THD *thd __attribute__((unused)),
 
4083
bool create_table_precheck(Session *thd __attribute__((unused)),
4084
4084
                           TableList *tables __attribute__((unused)),
4085
4085
                           TableList *create_table)
4086
4086
{
4108
4108
    negated expression
4109
4109
*/
4110
4110
 
4111
 
Item *negate_expression(THD *thd, Item *expr)
 
4111
Item *negate_expression(Session *thd, Item *expr)
4112
4112
{
4113
4113
  Item *negated;
4114
4114
  if (expr->type() == Item::FUNC_ITEM &&
4289
4289
    @retval true on parsing error.
4290
4290
*/
4291
4291
 
4292
 
bool parse_sql(THD *thd, Lex_input_stream *lip)
 
4292
bool parse_sql(Session *thd, Lex_input_stream *lip)
4293
4293
{
4294
4294
  assert(thd->m_lip == NULL);
4295
4295