~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: patrick crews
  • Date: 2011-02-23 17:17:25 UTC
  • mto: (2195.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2196.
  • Revision ID: gleebix@gmail.com-20110223171725-4tgewemxhsw1m7q8
Integrated randgen with dbqp.  We now have mode=randgen and a set of randgen test suites (very basic now).  Output = same as dtr : )  We also have mode=cleanup to kill any servers we have started.  Docs updates too.  Gendata utility allows us to populate test servers 

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
   along with this program; if not, write to the Free Software
14
14
   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */
15
15
 
16
 
#include "config.h"
 
16
#include <config.h>
17
17
 
18
18
#define DRIZZLE_LEX 1
19
19
 
 
20
#include <drizzled/item/num.h>
 
21
#include <drizzled/abort_exception.h>
20
22
#include <drizzled/my_hash.h>
21
23
#include <drizzled/error.h>
22
24
#include <drizzled/nested_join.h>
23
25
#include <drizzled/query_id.h>
24
 
#include "drizzled/transaction_services.h"
 
26
#include <drizzled/transaction_services.h>
25
27
#include <drizzled/sql_parse.h>
26
28
#include <drizzled/data_home.h>
27
29
#include <drizzled/sql_base.h>
28
30
#include <drizzled/show.h>
29
 
#include <drizzled/db.h>
30
31
#include <drizzled/function/time/unix_timestamp.h>
31
32
#include <drizzled/function/get_system_var.h>
32
33
#include <drizzled/item/cmpfunc.h>
33
34
#include <drizzled/item/null.h>
34
35
#include <drizzled/session.h>
 
36
#include <drizzled/session/cache.h>
35
37
#include <drizzled/sql_load.h>
36
38
#include <drizzled/lock.h>
37
39
#include <drizzled/select_send.h>
38
40
#include <drizzled/plugin/client.h>
39
41
#include <drizzled/statement.h>
40
42
#include <drizzled/statement/alter_table.h>
41
 
#include "drizzled/probes.h"
42
 
#include "drizzled/session/cache.h"
43
 
#include "drizzled/global_charset_info.h"
44
 
 
45
 
#include "drizzled/plugin/logging.h"
46
 
#include "drizzled/plugin/query_rewrite.h"
47
 
#include "drizzled/plugin/query_cache.h"
48
 
#include "drizzled/plugin/authorization.h"
49
 
#include "drizzled/optimizer/explain_plan.h"
50
 
#include "drizzled/pthread_globals.h"
51
 
#include "drizzled/plugin/event_observer.h"
 
43
#include <drizzled/probes.h>
 
44
#include <drizzled/global_charset_info.h>
 
45
 
 
46
#include <drizzled/plugin/logging.h>
 
47
#include <drizzled/plugin/query_rewrite.h>
 
48
#include <drizzled/plugin/query_cache.h>
 
49
#include <drizzled/plugin/authorization.h>
 
50
#include <drizzled/optimizer/explain_plan.h>
 
51
#include <drizzled/pthread_globals.h>
 
52
#include <drizzled/plugin/event_observer.h>
 
53
#include <drizzled/visibility.h>
 
54
 
 
55
#include <drizzled/schema.h>
52
56
 
53
57
#include <limits.h>
54
58
 
55
59
#include <bitset>
56
60
#include <algorithm>
57
61
#include <boost/date_time.hpp>
58
 
#include "drizzled/internal/my_sys.h"
 
62
#include <drizzled/internal/my_sys.h>
59
63
 
60
64
using namespace std;
61
65
 
62
 
extern int DRIZZLEparse(void *session); // from sql_yacc.cc
 
66
extern int base_sql_parse(drizzled::Session *session); // from sql_yacc.cc
63
67
 
64
68
namespace drizzled
65
69
{
66
70
 
67
71
/* Prototypes */
68
 
bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize);
 
72
bool my_yyoverflow(short **a, ParserType **b, ulong *yystacksize);
69
73
static bool parse_sql(Session *session, Lex_input_stream *lip);
70
 
void mysql_parse(Session *session, const char *inBuf, uint32_t length);
 
74
void parse(Session *session, const char *inBuf, uint32_t length);
71
75
 
72
76
/**
73
77
  @defgroup Runtime_Environment Runtime Environment
77
81
extern size_t my_thread_stack_size;
78
82
extern const CHARSET_INFO *character_set_filesystem;
79
83
 
80
 
const LEX_STRING command_name[COM_END+1]={
81
 
  { C_STRING_WITH_LEN("Sleep") },
82
 
  { C_STRING_WITH_LEN("Quit") },
83
 
  { C_STRING_WITH_LEN("Init DB") },
84
 
  { C_STRING_WITH_LEN("Query") },
85
 
  { C_STRING_WITH_LEN("Shutdown") },
86
 
  { C_STRING_WITH_LEN("Connect") },
87
 
  { C_STRING_WITH_LEN("Ping") },
88
 
  { C_STRING_WITH_LEN("Error") }  // Last command number
 
84
namespace
 
85
{
 
86
 
 
87
static const std::string command_name[COM_END+1]={
 
88
  "Sleep",
 
89
  "Quit",
 
90
  "Init DB",
 
91
  "Query",
 
92
  "Shutdown",
 
93
  "Connect",
 
94
  "Ping",
 
95
  "Error"  // Last command number
89
96
};
90
97
 
 
98
}
 
99
 
91
100
const char *xa_state_names[]={
92
101
  "NON-EXISTING", "ACTIVE", "IDLE", "PREPARED"
93
102
};
106
115
*/
107
116
bitset<CF_BIT_SIZE> sql_command_flags[SQLCOM_END+1];
108
117
 
 
118
const std::string &getCommandName(const enum_server_command& command)
 
119
{
 
120
  return command_name[command];
 
121
}
 
122
 
109
123
void init_update_queries(void)
110
124
{
111
125
  uint32_t x;
154
168
                         can be zero.
155
169
 
156
170
  @todo
157
 
    set session->lex->sql_command to SQLCOM_END here.
 
171
    set session->getLex()->sql_command to SQLCOM_END here.
158
172
  @todo
159
173
    The following has to be changed to an 8 byte integer
160
174
 
173
187
  DRIZZLE_COMMAND_START(session->thread_id, command);
174
188
 
175
189
  session->command= command;
176
 
  session->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
 
190
  session->getLex()->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
177
191
  session->set_time();
178
192
  session->setQueryId(query_id.value());
179
193
 
187
201
    query_id.next();
188
202
  }
189
203
 
190
 
  /* TODO: set session->lex->sql_command to SQLCOM_END here */
 
204
  /* @todo set session->getLex()->sql_command to SQLCOM_END here */
191
205
 
192
206
  plugin::Logging::preDo(session);
193
207
  if (unlikely(plugin::EventObserver::beforeStatement(*session)))
208
222
 
209
223
    string tmp(packet, packet_length);
210
224
 
211
 
    SchemaIdentifier identifier(tmp);
 
225
    identifier::Schema identifier(tmp);
212
226
 
213
 
    if (not mysql_change_db(session, identifier))
 
227
    if (not schema::change(*session, identifier))
214
228
    {
215
229
      session->my_ok();
216
230
    }
224
238
                        session->thread_id,
225
239
                        const_cast<const char *>(session->schema()->c_str()));
226
240
 
227
 
    mysql_parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
 
241
    parse(session, session->getQueryString()->c_str(), session->getQueryString()->length());
228
242
 
229
243
    break;
230
244
  }
257
271
  /* If commit fails, we should be able to reset the OK status. */
258
272
  session->main_da.can_overwrite_status= true;
259
273
  TransactionServices &transaction_services= TransactionServices::singleton();
260
 
  transaction_services.autocommitOrRollback(session, session->is_error());
 
274
  transaction_services.autocommitOrRollback(*session, session->is_error());
261
275
  session->main_da.can_overwrite_status= false;
262
276
 
263
277
  session->transaction.stmt.reset();
282
296
  {
283
297
  case Diagnostics_area::DA_ERROR:
284
298
    /* The query failed, send error to log and abort bootstrap. */
285
 
    session->client->sendError(session->main_da.sql_errno(),
 
299
    session->getClient()->sendError(session->main_da.sql_errno(),
286
300
                               session->main_da.message());
287
301
    break;
288
302
 
289
303
  case Diagnostics_area::DA_EOF:
290
 
    session->client->sendEOF();
 
304
    session->getClient()->sendEOF();
291
305
    break;
292
306
 
293
307
  case Diagnostics_area::DA_OK:
294
 
    session->client->sendOK();
 
308
    session->getClient()->sendOK();
295
309
    break;
296
310
 
297
311
  case Diagnostics_area::DA_DISABLED:
299
313
 
300
314
  case Diagnostics_area::DA_EMPTY:
301
315
  default:
302
 
    session->client->sendOK();
 
316
    session->getClient()->sendOK();
303
317
    break;
304
318
  }
305
319
 
429
443
    true        Error
430
444
*/
431
445
 
432
 
static int mysql_execute_command(Session *session)
 
446
static int execute_command(Session *session)
433
447
{
434
448
  bool res= false;
435
 
  LEX  *lex= session->lex;
 
449
 
436
450
  /* first Select_Lex (have special meaning for many of non-SELECTcommands) */
437
 
  Select_Lex *select_lex= &lex->select_lex;
 
451
  Select_Lex *select_lex= &session->getLex()->select_lex;
 
452
 
438
453
  /* list of all tables in query */
439
454
  TableList *all_tables;
440
455
 
453
468
    assert(first_table == all_tables);
454
469
    assert(first_table == all_tables && first_table != 0);
455
470
  */
456
 
  lex->first_lists_tables_same();
 
471
  session->getLex()->first_lists_tables_same();
 
472
 
457
473
  /* should be assigned after making first tables same */
458
 
  all_tables= lex->query_tables;
 
474
  all_tables= session->getLex()->query_tables;
 
475
 
459
476
  /* set context for commands which do not use setup_tables */
460
 
  select_lex->
461
 
    context.resolve_in_table_list_only((TableList*)select_lex->
462
 
                                       table_list.first);
 
477
  select_lex->context.resolve_in_table_list_only((TableList*)select_lex->table_list.first);
463
478
 
464
479
  /*
465
480
    Reset warning count for each query that uses tables
468
483
    variables, but for now this is probably good enough.
469
484
    Don't reset warnings when executing a stored routine.
470
485
  */
471
 
  if (all_tables || ! lex->is_single_level_stmt())
 
486
  if (all_tables || ! session->getLex()->is_single_level_stmt())
472
487
  {
473
488
    drizzle_reset_errors(session, 0);
474
489
  }
475
490
 
476
491
  assert(session->transaction.stmt.hasModifiedNonTransData() == false);
477
492
 
 
493
  if (! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
 
494
      && ! session->inTransaction()
 
495
      && session->getLex()->statement->isTransactional())
 
496
  {
 
497
    if (session->startTransaction() == false)
 
498
    {
 
499
      my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
 
500
      return true;
 
501
    }
 
502
  }
 
503
 
478
504
  /* now we are ready to execute the statement */
479
 
  res= lex->statement->execute();
 
505
  res= session->getLex()->statement->execute();
480
506
  session->set_proc_info("query end");
481
507
  /*
482
508
    The return value for ROW_COUNT() is "implementation dependent" if the
484
510
    wants. We also keep the last value in case of SQLCOM_CALL or
485
511
    SQLCOM_EXECUTE.
486
512
  */
487
 
  if (! (sql_command_flags[lex->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
 
513
  if (! (sql_command_flags[session->getLex()->sql_command].test(CF_BIT_HAS_ROW_COUNT)))
488
514
  {
489
515
    session->row_count_func= -1;
490
516
  }
493
519
}
494
520
bool execute_sqlcom_select(Session *session, TableList *all_tables)
495
521
{
496
 
  LEX   *lex= session->lex;
 
522
  LEX   *lex= session->getLex();
497
523
  select_result *result=lex->result;
498
524
  bool res= false;
499
525
  /* assign global limit variable if limit is not given */
503
529
      param->select_limit=
504
530
        new Item_int((uint64_t) session->variables.select_limit);
505
531
  }
 
532
 
 
533
  if (all_tables
 
534
      && ! (session->server_status & SERVER_STATUS_AUTOCOMMIT)
 
535
      && ! session->inTransaction()
 
536
      && ! lex->statement->isShow())
 
537
  {
 
538
    if (session->startTransaction() == false)
 
539
    {
 
540
      my_error(drizzled::ER_UNKNOWN_ERROR, MYF(0));
 
541
      return true;
 
542
    }
 
543
  }
 
544
 
506
545
  if (not (res= session->openTablesLock(all_tables)))
507
546
  {
508
547
    if (lex->describe)
517
556
        return true;
518
557
      session->send_explain_fields(result);
519
558
      optimizer::ExplainPlan planner;
520
 
      res= planner.explainUnion(session, &session->lex->unit, result);
 
559
      res= planner.explainUnion(session, &session->getLex()->unit, result);
521
560
      if (lex->describe & DESCRIBE_EXTENDED)
522
561
      {
523
562
        char buff[1024];
524
563
        String str(buff,(uint32_t) sizeof(buff), system_charset_info);
525
564
        str.length(0);
526
 
        session->lex->unit.print(&str, QT_ORDINARY);
 
565
        session->getLex()->unit.print(&str, QT_ORDINARY);
527
566
        str.append('\0');
528
567
        push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE,
529
568
                     ER_YES, str.ptr());
532
571
        result->abort();
533
572
      else
534
573
        result->send_eof();
 
574
 
535
575
      delete result;
536
576
    }
537
577
    else
556
596
#define MY_YACC_INIT 1000                       // Start with big alloc
557
597
#define MY_YACC_MAX  32000                      // Because of 'short'
558
598
 
559
 
bool my_yyoverflow(short **yyss, YYSTYPE **yyvs, ulong *yystacksize)
 
599
bool my_yyoverflow(short **yyss, ParserType **yyvs, ulong *yystacksize)
560
600
{
561
 
  LEX   *lex= current_session->lex;
 
601
  LEX   *lex= current_session->getLex();
562
602
  ulong old_info=0;
563
603
  if ((uint32_t) *yystacksize >= MY_YACC_MAX)
564
604
    return 1;
581
621
    memcpy(lex->yacc_yyvs, *yyvs, old_info*sizeof(**yyvs));
582
622
  }
583
623
  *yyss=(short*) lex->yacc_yyss;
584
 
  *yyvs=(YYSTYPE*) lex->yacc_yyvs;
 
624
  *yyvs=(ParserType*) lex->yacc_yyvs;
585
625
  return 0;
586
626
}
587
627
 
588
628
 
589
629
void
590
 
mysql_init_select(LEX *lex)
 
630
init_select(LEX *lex)
591
631
{
592
632
  Select_Lex *select_lex= lex->current_select;
593
633
  select_lex->init_select();
601
641
 
602
642
 
603
643
bool
604
 
mysql_new_select(LEX *lex, bool move_down)
 
644
new_select(LEX *lex, bool move_down)
605
645
{
606
646
  Select_Lex *select_lex;
607
647
  Session *session= lex->session;
608
648
 
609
649
  if (!(select_lex= new (session->mem_root) Select_Lex()))
610
 
    return(1);
 
650
    return true;
 
651
 
611
652
  select_lex->select_number= ++session->select_number;
612
653
  select_lex->parent_lex= lex; /* Used in init_query. */
613
654
  select_lex->init_query();
614
655
  select_lex->init_select();
615
656
  lex->nest_level++;
 
657
 
616
658
  if (lex->nest_level > (int) MAX_SELECT_NESTING)
617
659
  {
618
660
    my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
619
661
    return(1);
620
662
  }
 
663
 
621
664
  select_lex->nest_level= lex->nest_level;
622
665
  if (move_down)
623
666
  {
645
688
    if (lex->current_select->order_list.first && !lex->current_select->braces)
646
689
    {
647
690
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "order_st BY");
648
 
      return(1);
 
691
      return true;
649
692
    }
 
693
 
650
694
    select_lex->include_neighbour(lex->current_select);
651
695
    Select_Lex_Unit *unit= select_lex->master_unit();
652
 
    if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
653
 
      return(1);
 
696
 
 
697
    if (not unit->fake_select_lex && unit->add_fake_select_lex(lex->session))
 
698
      return true;
 
699
 
654
700
    select_lex->context.outer_context=
655
701
                unit->first_select()->context.outer_context;
656
702
  }
663
709
    list
664
710
  */
665
711
  select_lex->context.resolve_in_select_list= true;
666
 
  return(0);
 
712
 
 
713
  return false;
667
714
}
668
715
 
669
716
/**
676
723
  @param var_name               Variable name
677
724
*/
678
725
 
679
 
void create_select_for_variable(const char *var_name)
 
726
void create_select_for_variable(Session *session, const char *var_name)
680
727
{
681
 
  Session *session;
682
728
  LEX *lex;
683
729
  LEX_STRING tmp, null_lex_string;
684
730
  Item *var;
685
731
  char buff[MAX_SYS_VAR_LENGTH*2+4+8];
686
732
  char *end= buff;
687
733
 
688
 
  session= current_session;
689
 
  lex= session->lex;
690
 
  mysql_init_select(lex);
 
734
  lex= session->getLex();
 
735
  init_select(lex);
691
736
  lex->sql_command= SQLCOM_SELECT;
692
737
  tmp.str= (char*) var_name;
693
738
  tmp.length=strlen(var_name);
702
747
    var->set_name(buff, end-buff, system_charset_info);
703
748
    session->add_item_to_list(var);
704
749
  }
705
 
  return;
706
750
}
707
751
 
708
752
 
714
758
  @param       length  Length of the query text
715
759
*/
716
760
 
717
 
void mysql_parse(Session *session, const char *inBuf, uint32_t length)
 
761
void parse(Session *session, const char *inBuf, uint32_t length)
718
762
{
719
 
  boost::posix_time::ptime start_time=boost::posix_time::microsec_clock::local_time();
720
 
  session->lex->start(session);
 
763
  session->getLex()->start(session);
721
764
 
722
765
  session->reset_for_next_command();
723
766
  /* Check if the Query is Cached if and return true if yes
733
776
  {
734
777
    return;
735
778
  }
736
 
  LEX *lex= session->lex;
 
779
  LEX *lex= session->getLex();
737
780
  Lex_input_stream lip(session, inBuf, length);
738
781
  bool err= parse_sql(session, &lip);
739
782
  if (!err)
748
791
        /* Actually execute the query */
749
792
        try 
750
793
        {
751
 
          mysql_execute_command(session);
 
794
          execute_command(session);
752
795
        }
753
796
        catch (...)
754
797
        {
755
798
          // Just try to catch any random failures that could have come
756
799
          // during execution.
757
 
          unireg_abort(1);
 
800
          DRIZZLE_ABORT;
758
801
        }
759
802
        DRIZZLE_QUERY_EXEC_DONE(0);
760
803
      }
768
811
  session->set_proc_info("freeing items");
769
812
  session->end_statement();
770
813
  session->cleanup_after_query();
771
 
  boost::posix_time::ptime end_time=boost::posix_time::microsec_clock::local_time();
772
 
  session->status_var.execution_time_nsec+=(end_time-start_time).total_microseconds();
 
814
  session->set_end_timer();
773
815
}
774
816
 
775
817
 
791
833
                       List<String> *interval_list, const CHARSET_INFO * const cs)
792
834
{
793
835
  register CreateField *new_field;
794
 
  LEX  *lex= session->lex;
 
836
  LEX  *lex= session->getLex();
795
837
  statement::AlterTable *statement= (statement::AlterTable *)lex->statement;
796
838
 
797
839
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
805
847
                      &default_key_create_info,
806
848
                      0, lex->col_list);
807
849
    statement->alter_info.key_list.push_back(key);
808
 
    lex->col_list.empty();
 
850
    lex->col_list.clear();
809
851
  }
810
852
  if (type_modifier & (UNIQUE_FLAG | UNIQUE_KEY_FLAG))
811
853
  {
815
857
                 &default_key_create_info, 0,
816
858
                 lex->col_list);
817
859
    statement->alter_info.key_list.push_back(key);
818
 
    lex->col_list.empty();
 
860
    lex->col_list.clear();
819
861
  }
820
862
 
821
863
  if (default_value)
829
871
    */
830
872
    if (default_value->type() == Item::FUNC_ITEM &&
831
873
        !(((Item_func*)default_value)->functype() == Item_func::NOW_FUNC &&
832
 
         type == DRIZZLE_TYPE_TIMESTAMP))
 
874
         (type == DRIZZLE_TYPE_TIMESTAMP or type == DRIZZLE_TYPE_MICROTIME)))
833
875
    {
834
876
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
835
877
      return true;
837
879
    else if (default_value->type() == Item::NULL_ITEM)
838
880
    {
839
881
      default_value= 0;
840
 
      if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) ==
841
 
          NOT_NULL_FLAG)
 
882
      if ((type_modifier & (NOT_NULL_FLAG | AUTO_INCREMENT_FLAG)) == NOT_NULL_FLAG)
842
883
      {
843
884
        my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
844
885
        return true;
851
892
    }
852
893
  }
853
894
 
854
 
  if (on_update_value && type != DRIZZLE_TYPE_TIMESTAMP)
 
895
  if (on_update_value && (type != DRIZZLE_TYPE_TIMESTAMP and type != DRIZZLE_TYPE_MICROTIME))
855
896
  {
856
897
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
857
898
    return true;
870
911
}
871
912
 
872
913
 
873
 
/** Store position for column in ALTER TABLE .. ADD column. */
874
 
 
875
 
void store_position_for_column(const char *name)
876
 
{
877
 
  current_session->lex->last_field->after=const_cast<char*> (name);
878
 
}
879
 
 
880
914
/**
881
915
  Add a table to list of used tables.
882
916
 
897
931
*/
898
932
 
899
933
TableList *Select_Lex::add_table_to_list(Session *session,
900
 
                                                             Table_ident *table,
901
 
                                                             LEX_STRING *alias,
902
 
                                                             const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
903
 
                                                             thr_lock_type lock_type,
904
 
                                                             List<Index_hint> *index_hints_arg,
 
934
                                         Table_ident *table,
 
935
                                         LEX_STRING *alias,
 
936
                                         const bitset<NUM_OF_TABLE_OPTIONS>& table_options,
 
937
                                         thr_lock_type lock_type,
 
938
                                         List<Index_hint> *index_hints_arg,
905
939
                                         LEX_STRING *option)
906
940
{
907
941
  TableList *ptr;
908
942
  TableList *previous_table_ref; /* The table preceding the current one. */
909
943
  char *alias_str;
910
 
  LEX *lex= session->lex;
 
944
  LEX *lex= session->getLex();
911
945
 
912
946
  if (!table)
913
947
    return NULL;                                // End of memory
923
957
  {
924
958
    my_casedn_str(files_charset_info, table->db.str);
925
959
 
926
 
    SchemaIdentifier schema_identifier(string(table->db.str));
927
 
    if (not check_db_name(session, schema_identifier))
 
960
    identifier::Schema schema_identifier(string(table->db.str));
 
961
    if (not schema::check(*session, schema_identifier))
928
962
    {
929
963
 
930
964
      my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
940
974
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
941
975
      return NULL;
942
976
    }
943
 
    if (!(alias_str= (char*) session->memdup(alias_str,table->table.length+1)))
 
977
    if (!(alias_str= (char*) session->getMemRoot()->duplicate(alias_str,table->table.length+1)))
944
978
      return NULL;
945
979
  }
946
980
  if (!(ptr = (TableList *) session->calloc(sizeof(TableList))))
976
1010
         tables ;
977
1011
         tables=tables->next_local)
978
1012
    {
979
 
      if (!my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
980
 
          !strcasecmp(ptr->getSchemaName(), tables->getSchemaName()))
 
1013
      if (not my_strcasecmp(table_alias_charset, alias_str, tables->alias) &&
 
1014
          not my_strcasecmp(system_charset_info, ptr->getSchemaName(), tables->getSchemaName()))
981
1015
      {
982
1016
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str);
983
1017
        return NULL;
1041
1075
bool Select_Lex::init_nested_join(Session *session)
1042
1076
{
1043
1077
  TableList *ptr;
1044
 
  nested_join_st *nested_join;
 
1078
  NestedJoin *nested_join;
1045
1079
 
1046
1080
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1047
 
                                       sizeof(nested_join_st))))
 
1081
                                       sizeof(NestedJoin))))
1048
1082
    return true;
1049
 
  ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
 
1083
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1050
1084
  nested_join= ptr->getNestedJoin();
1051
1085
  join_list->push_front(ptr);
1052
1086
  ptr->setEmbedding(embedding);
1054
1088
  ptr->alias= (char*) "(nested_join)";
1055
1089
  embedding= ptr;
1056
1090
  join_list= &nested_join->join_list;
1057
 
  join_list->empty();
 
1091
  join_list->clear();
1058
1092
  return false;
1059
1093
}
1060
1094
 
1076
1110
TableList *Select_Lex::end_nested_join(Session *)
1077
1111
{
1078
1112
  TableList *ptr;
1079
 
  nested_join_st *nested_join;
 
1113
  NestedJoin *nested_join;
1080
1114
 
1081
1115
  assert(embedding);
1082
1116
  ptr= embedding;
1117
1151
TableList *Select_Lex::nest_last_join(Session *session)
1118
1152
{
1119
1153
  TableList *ptr;
1120
 
  nested_join_st *nested_join;
 
1154
  NestedJoin *nested_join;
1121
1155
  List<TableList> *embedded_list;
1122
1156
 
1123
1157
  if (!(ptr= (TableList*) session->calloc(ALIGN_SIZE(sizeof(TableList))+
1124
 
                                          sizeof(nested_join_st))))
 
1158
                                          sizeof(NestedJoin))))
1125
1159
    return NULL;
1126
 
  ptr->setNestedJoin(((nested_join_st*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
 
1160
  ptr->setNestedJoin(((NestedJoin*) ((unsigned char*) ptr + ALIGN_SIZE(sizeof(TableList)))));
1127
1161
  nested_join= ptr->getNestedJoin();
1128
1162
  ptr->setEmbedding(embedding);
1129
1163
  ptr->setJoinList(join_list);
1130
1164
  ptr->alias= (char*) "(nest_last_join)";
1131
1165
  embedded_list= &nested_join->join_list;
1132
 
  embedded_list->empty();
 
1166
  embedded_list->clear();
1133
1167
 
1134
1168
  for (uint32_t i=0; i < 2; i++)
1135
1169
  {
1277
1311
  fake_select_lex->include_standalone(this,
1278
1312
                                      (Select_Lex_Node**)&fake_select_lex);
1279
1313
  fake_select_lex->select_number= INT_MAX;
1280
 
  fake_select_lex->parent_lex= session_arg->lex; /* Used in init_query. */
 
1314
  fake_select_lex->parent_lex= session_arg->getLex(); /* Used in init_query. */
1281
1315
  fake_select_lex->make_empty_select();
1282
1316
  fake_select_lex->linkage= GLOBAL_OPTIONS_TYPE;
1283
1317
  fake_select_lex->select_limit= 0;
1297
1331
    */
1298
1332
    global_parameters= fake_select_lex;
1299
1333
    fake_select_lex->no_table_names_allowed= 1;
1300
 
    session_arg->lex->current_select= fake_select_lex;
 
1334
    session_arg->getLex()->current_select= fake_select_lex;
1301
1335
  }
1302
 
  session_arg->lex->pop_context();
 
1336
  session_arg->getLex()->pop_context();
1303
1337
  return(0);
1304
1338
}
1305
1339
 
1335
1369
    left_op->first_leaf_for_name_resolution();
1336
1370
  on_context->last_name_resolution_table=
1337
1371
    right_op->last_leaf_for_name_resolution();
1338
 
  return session->lex->push_context(on_context);
 
1372
  return session->getLex()->push_context(on_context);
1339
1373
}
1340
1374
 
1341
1375
 
1423
1457
    1   error   ; In this case the error messege is sent to the client
1424
1458
*/
1425
1459
 
1426
 
bool check_simple_select()
 
1460
bool check_simple_select(Session::pointer session)
1427
1461
{
1428
 
  Session *session= current_session;
1429
 
  LEX *lex= session->lex;
1430
 
  if (lex->current_select != &lex->select_lex)
 
1462
  if (session->getLex()->current_select != &session->getLex()->select_lex)
1431
1463
  {
1432
1464
    char command[80];
1433
1465
    Lex_input_stream *lip= session->m_lip;
1487
1519
bool update_precheck(Session *session, TableList *)
1488
1520
{
1489
1521
  const char *msg= 0;
1490
 
  LEX *lex= session->lex;
1491
 
  Select_Lex *select_lex= &lex->select_lex;
 
1522
  Select_Lex *select_lex= &session->getLex()->select_lex;
1492
1523
 
1493
 
  if (session->lex->select_lex.item_list.elements != session->lex->value_list.elements)
 
1524
  if (session->getLex()->select_lex.item_list.elements != session->getLex()->value_list.elements)
1494
1525
  {
1495
1526
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1496
1527
    return(true);
1497
1528
  }
1498
1529
 
1499
 
  if (session->lex->select_lex.table_list.elements > 1)
 
1530
  if (session->getLex()->select_lex.table_list.elements > 1)
1500
1531
  {
1501
1532
    if (select_lex->order_list.elements)
1502
1533
      msg= "ORDER BY";
1526
1557
 
1527
1558
bool insert_precheck(Session *session, TableList *)
1528
1559
{
1529
 
  LEX *lex= session->lex;
1530
 
 
1531
1560
  /*
1532
1561
    Check that we have modify privileges for the first table and
1533
1562
    select privileges for the rest
1534
1563
  */
1535
 
  if (lex->update_list.elements != lex->value_list.elements)
 
1564
  if (session->getLex()->update_list.elements != session->getLex()->value_list.elements)
1536
1565
  {
1537
1566
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
1538
1567
    return(true);
1559
1588
  {
1560
1589
    /* it is NOT(NOT( ... )) */
1561
1590
    Item *arg= ((Item_func *) expr)->arguments()[0];
1562
 
    enum_parsing_place place= session->lex->current_select->parsing_place;
 
1591
    enum_parsing_place place= session->getLex()->current_select->parsing_place;
1563
1592
    if (arg->is_bool_func() || place == IN_WHERE || place == IN_HAVING)
1564
1593
      return arg;
1565
1594
    /*
1608
1637
}
1609
1638
 
1610
1639
 
1611
 
bool check_identifier_name(LEX_STRING *str, uint32_t err_code,
 
1640
bool check_identifier_name(LEX_STRING *str, error_t err_code,
1612
1641
                           uint32_t max_char_length,
1613
1642
                           const char *param_for_err_msg)
1614
1643
{
1634
1663
 
1635
1664
  switch (err_code)
1636
1665
  {
1637
 
  case 0:
 
1666
  case EE_OK:
1638
1667
    break;
1639
1668
  case ER_WRONG_STRING_LENGTH:
1640
1669
    my_error(err_code, MYF(0), str->str, param_for_err_msg, max_char_length);
1646
1675
    assert(0);
1647
1676
    break;
1648
1677
  }
 
1678
 
1649
1679
  return true;
1650
1680
}
1651
1681
 
1674
1704
 
1675
1705
  /* Parse the query. */
1676
1706
 
1677
 
  bool mysql_parse_status= DRIZZLEparse(session) != 0;
 
1707
  bool parse_status= base_sql_parse(session) != 0;
1678
1708
 
1679
1709
  /* Check that if DRIZZLEparse() failed, session->is_error() is set. */
1680
1710
 
1681
 
  assert(!mysql_parse_status || session->is_error());
 
1711
  assert(!parse_status || session->is_error());
1682
1712
 
1683
1713
  /* Reset Lex_input_stream. */
1684
1714
 
1685
1715
  session->m_lip= NULL;
1686
1716
 
1687
 
  DRIZZLE_QUERY_PARSE_DONE(mysql_parse_status || session->is_fatal_error);
 
1717
  DRIZZLE_QUERY_PARSE_DONE(parse_status || session->is_fatal_error);
1688
1718
 
1689
1719
  /* That's it. */
1690
1720
 
1691
 
  return mysql_parse_status || session->is_fatal_error;
 
1721
  return parse_status || session->is_fatal_error;
1692
1722
}
1693
1723
 
1694
1724
/**