~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_yacc.yy

Merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
*/
28
28
#define YYPARSE_PARAM yysession
29
29
#define YYLEX_PARAM yysession
30
 
#define YYSession ((Session *)yysession)
 
30
#define YYSession (static_cast<Session *>(yysession))
31
31
 
32
32
#define YYENABLE_NLS 0
33
33
#define YYLTYPE_IS_TRIVIAL 0
36
36
#define YYINITDEPTH 100
37
37
#define YYMAXDEPTH 3200                        /* Because of 64K stack */
38
38
#define Lex (YYSession->lex)
39
 
#define Select Lex->current_select
40
39
#include <drizzled/server_includes.h>
41
40
#include <drizzled/lex_symbol.h>
42
41
#include <drizzled/function/locate.h>
88
87
#include <drizzled/function/get_system_var.h>
89
88
#include <mysys/thr_lock.h>
90
89
#include <drizzled/message/table.pb.h>
 
90
#include <drizzled/command.h>
 
91
#include <drizzled/command/show_status.h>
 
92
#include <drizzled/command/select.h>
 
93
 
 
94
using namespace drizzled;
91
95
 
92
96
class Table_ident;
93
97
class Item;
1214
1218
          field_list ')' opt_create_table_options
1215
1219
          create3 {}
1216
1220
        |  create_select ')'
1217
 
           { Select->set_braces(1);}
 
1221
           { Lex->current_select->set_braces(1);}
1218
1222
           union_opt {}
1219
1223
        ;
1220
1224
 
1221
1225
create3:
1222
1226
          /* empty */ {}
1223
1227
        | opt_duplicate opt_as create_select
1224
 
          { Select->set_braces(0);}
 
1228
          { Lex->current_select->set_braces(0);}
1225
1229
          union_clause {}
1226
1230
        | opt_duplicate opt_as '(' create_select ')'
1227
 
          { Select->set_braces(1);}
 
1231
          { Lex->current_select->set_braces(1);}
1228
1232
          union_opt {}
1229
1233
        ;
1230
1234
 
1247
1251
          }
1248
1252
          select_options select_item_list
1249
1253
          {
1250
 
            Select->parsing_place= NO_MATTER;
 
1254
            Lex->current_select->parsing_place= NO_MATTER;
1251
1255
          }
1252
1256
          opt_select_from
1253
1257
          {
1447
1451
storage_engines:
1448
1452
          ident_or_text
1449
1453
          {
1450
 
            StorageEngine *engine= ha_resolve_by_name(YYSession, &$1);
 
1454
            const std::string engine_name($1.str);
 
1455
            StorageEngine *engine= ha_resolve_by_name(YYSession, engine_name);
1451
1456
 
1452
1457
            if (engine)
1453
1458
              $$= engine;
1462
1467
known_storage_engines:
1463
1468
          ident_or_text
1464
1469
          {
 
1470
            const std::string engine_name($1.str);
1465
1471
            StorageEngine *engine;
1466
 
            if ((engine= ha_resolve_by_name(YYSession, &$1)))
 
1472
            if ((engine= ha_resolve_by_name(YYSession, engine_name)))
1467
1473
              $$= engine;
1468
1474
            else
1469
1475
            {
2465
2471
assign_to_keycache:
2466
2472
          table_ident cache_keys_spec
2467
2473
          {
2468
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, 0, TL_READ, 
2469
 
                                           Select->pop_index_hints()))
 
2474
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL,
 
2475
                   0, TL_READ, Lex->current_select->pop_index_hints()))
2470
2476
              DRIZZLE_YYABORT;
2471
2477
          }
2472
2478
        ;
2479
2485
cache_keys_spec:
2480
2486
          {
2481
2487
            Lex->select_lex.alloc_index_hints(YYSession);
2482
 
            Select->set_index_hint_type(INDEX_HINT_USE, INDEX_HINT_MASK_ALL);
 
2488
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE,
 
2489
                                                     INDEX_HINT_MASK_ALL);
2483
2490
          }
2484
2491
          cache_key_list_or_empty
2485
2492
        ;
2499
2506
          {
2500
2507
            LEX *lex= Lex;
2501
2508
            lex->sql_command= SQLCOM_SELECT;
 
2509
            lex->command= new(std::nothrow) command::Select(SQLCOM_SELECT,
 
2510
                                                            YYSession);
 
2511
            if (lex->command == NULL)
 
2512
              DRIZZLE_YYABORT;
2502
2513
          }
2503
2514
        ;
2504
2515
 
2557
2568
          }
2558
2569
          select_options select_item_list
2559
2570
          {
2560
 
            Select->parsing_place= NO_MATTER;
 
2571
            Lex->current_select->parsing_place= NO_MATTER;
2561
2572
          }
2562
2573
          select_into select_lock_type
2563
2574
        ;
2574
2585
          FROM join_table_list where_clause group_clause having_clause
2575
2586
          opt_order_clause opt_limit_clause
2576
2587
          {
2577
 
            Select->context.table_list=
2578
 
              Select->context.first_name_resolution_table= 
2579
 
                (TableList *) Select->table_list.first;
 
2588
            Lex->current_select->context.table_list=
 
2589
              Lex->current_select->context.first_name_resolution_table= 
 
2590
                reinterpret_cast<TableList *>(Lex->current_select->table_list.first);
2580
2591
          }
2581
2592
        ;
2582
2593
 
2584
2595
          /* empty*/
2585
2596
        | select_option_list
2586
2597
          {
2587
 
            if (Select->options & SELECT_DISTINCT && Select->options & SELECT_ALL)
 
2598
            if (Lex->current_select->options & SELECT_DISTINCT &&
 
2599
                Lex->current_select->options & SELECT_ALL)
2588
2600
            {
2589
2601
              my_error(ER_WRONG_USAGE, MYF(0), "ALL", "DISTINCT");
2590
2602
              DRIZZLE_YYABORT;
2598
2610
        ;
2599
2611
 
2600
2612
select_option:
2601
 
          STRAIGHT_JOIN { Select->options|= SELECT_STRAIGHT_JOIN; }
2602
 
        | DISTINCT         { Select->options|= SELECT_DISTINCT; }
2603
 
        | SQL_SMALL_RESULT { Select->options|= SELECT_SMALL_RESULT; }
2604
 
        | SQL_BIG_RESULT   { Select->options|= SELECT_BIG_RESULT; }
 
2613
          STRAIGHT_JOIN { Lex->current_select->options|= SELECT_STRAIGHT_JOIN; }
 
2614
        | DISTINCT         { Lex->current_select->options|= SELECT_DISTINCT; }
 
2615
        | SQL_SMALL_RESULT { Lex->current_select->options|= SELECT_SMALL_RESULT; }
 
2616
        | SQL_BIG_RESULT   { Lex->current_select->options|= SELECT_BIG_RESULT; }
2605
2617
        | SQL_BUFFER_RESULT
2606
2618
          {
2607
2619
            if (check_simple_select())
2608
2620
              DRIZZLE_YYABORT;
2609
 
            Select->options|= OPTION_BUFFER_RESULT;
 
2621
            Lex->current_select->options|= OPTION_BUFFER_RESULT;
2610
2622
          }
2611
2623
        | SQL_CALC_FOUND_ROWS
2612
2624
          {
2613
2625
            if (check_simple_select())
2614
2626
              DRIZZLE_YYABORT;
2615
 
            Select->options|= OPTION_FOUND_ROWS;
 
2627
            Lex->current_select->options|= OPTION_FOUND_ROWS;
2616
2628
          }
2617
 
        | ALL { Select->options|= SELECT_ALL; }
 
2629
        | ALL { Lex->current_select->options|= SELECT_ALL; }
2618
2630
        ;
2619
2631
 
2620
2632
select_lock_type:
3299
3311
        | COUNT_SYM '(' in_sum_expr ')'
3300
3312
          { $$=new Item_sum_count($3); }
3301
3313
        | COUNT_SYM '(' DISTINCT
3302
 
          { Select->in_sum_expr++; }
 
3314
          { Lex->current_select->in_sum_expr++; }
3303
3315
          expr_list
3304
 
          { Select->in_sum_expr--; }
 
3316
          { Lex->current_select->in_sum_expr--; }
3305
3317
          ')'
3306
3318
          { $$=new Item_sum_count_distinct(* $5); }
3307
3319
        | MIN_SYM '(' in_sum_expr ')'
3330
3342
        | SUM_SYM '(' DISTINCT in_sum_expr ')'
3331
3343
          { $$=new Item_sum_sum_distinct($4); }
3332
3344
        | GROUP_CONCAT_SYM '(' opt_distinct
3333
 
          { Select->in_sum_expr++; }
 
3345
          { Lex->current_select->in_sum_expr++; }
3334
3346
          expr_list opt_gorder_clause
3335
3347
          opt_gconcat_separator
3336
3348
          ')'
3337
3349
          {
3338
 
            Select_Lex *sel= Select;
 
3350
            Select_Lex *sel= Lex->current_select;
3339
3351
            sel->in_sum_expr--;
3340
3352
            $$=new Item_func_group_concat(Lex->current_context(), $3, $5,
3341
3353
                                          sel->gorder_list, $7);
3390
3402
opt_gorder_clause:
3391
3403
          /* empty */
3392
3404
          {
3393
 
            Select->gorder_list = NULL;
 
3405
            Lex->current_select->gorder_list = NULL;
3394
3406
          }
3395
3407
        | order_clause
3396
3408
          {
3397
 
            Select_Lex *select= Select;
 
3409
            Select_Lex *select= Lex->current_select;
3398
3410
            select->gorder_list=
3399
3411
              (SQL_LIST*) sql_memdup((char*) &select->order_list,
3400
3412
                                     sizeof(st_sql_list));
3414
3426
          }
3415
3427
          expr
3416
3428
          {
3417
 
            Select->in_sum_expr--;
 
3429
            Lex->current_select->in_sum_expr--;
3418
3430
            $$= $3;
3419
3431
          }
3420
3432
        ;
3533
3545
            /* Change the current name resolution context to a local context. */
3534
3546
            if (push_new_name_resolution_context(YYSession, $1, $3))
3535
3547
              DRIZZLE_YYABORT;
3536
 
            Select->parsing_place= IN_ON;
 
3548
            Lex->current_select->parsing_place= IN_ON;
3537
3549
          }
3538
3550
          expr
3539
3551
          {
3540
3552
            add_join_on($3,$6);
3541
3553
            Lex->pop_context();
3542
 
            Select->parsing_place= NO_MATTER;
 
3554
            Lex->current_select->parsing_place= NO_MATTER;
3543
3555
          }
3544
3556
        | table_ref STRAIGHT_JOIN table_factor
3545
3557
          ON
3548
3560
            /* Change the current name resolution context to a local context. */
3549
3561
            if (push_new_name_resolution_context(YYSession, $1, $3))
3550
3562
              DRIZZLE_YYABORT;
3551
 
            Select->parsing_place= IN_ON;
 
3563
            Lex->current_select->parsing_place= IN_ON;
3552
3564
          }
3553
3565
          expr
3554
3566
          {
3555
3567
            $3->straight=1;
3556
3568
            add_join_on($3,$6);
3557
3569
            Lex->pop_context();
3558
 
            Select->parsing_place= NO_MATTER;
 
3570
            Lex->current_select->parsing_place= NO_MATTER;
3559
3571
          }
3560
3572
        | table_ref normal_join table_ref
3561
3573
          USING
3563
3575
            DRIZZLE_YYABORT_UNLESS($1 && $3);
3564
3576
          }
3565
3577
          '(' using_list ')'
3566
 
          { add_join_natural($1,$3,$7,Select); $$=$3; }
 
3578
          { add_join_natural($1,$3,$7,Lex->current_select); $$=$3; }
3567
3579
        | table_ref NATURAL JOIN_SYM table_factor
3568
3580
          {
3569
3581
            DRIZZLE_YYABORT_UNLESS($1 && ($$=$4));
3570
 
            add_join_natural($1,$4,NULL,Select);
 
3582
            add_join_natural($1,$4,NULL,Lex->current_select);
3571
3583
          }
3572
3584
 
3573
3585
          /* LEFT JOIN variants */
3578
3590
            /* Change the current name resolution context to a local context. */
3579
3591
            if (push_new_name_resolution_context(YYSession, $1, $5))
3580
3592
              DRIZZLE_YYABORT;
3581
 
            Select->parsing_place= IN_ON;
 
3593
            Lex->current_select->parsing_place= IN_ON;
3582
3594
          }
3583
3595
          expr
3584
3596
          {
3586
3598
            Lex->pop_context();
3587
3599
            $5->outer_join|=JOIN_TYPE_LEFT;
3588
3600
            $$=$5;
3589
 
            Select->parsing_place= NO_MATTER;
 
3601
            Lex->current_select->parsing_place= NO_MATTER;
3590
3602
          }
3591
3603
        | table_ref LEFT opt_outer JOIN_SYM table_factor
3592
3604
          {
3594
3606
          }
3595
3607
          USING '(' using_list ')'
3596
3608
          { 
3597
 
            add_join_natural($1,$5,$9,Select); 
 
3609
            add_join_natural($1,$5,$9,Lex->current_select); 
3598
3610
            $5->outer_join|=JOIN_TYPE_LEFT; 
3599
3611
            $$=$5; 
3600
3612
          }
3601
3613
        | table_ref NATURAL LEFT opt_outer JOIN_SYM table_factor
3602
3614
          {
3603
3615
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3604
 
            add_join_natural($1,$6,NULL,Select);
 
3616
            add_join_natural($1,$6,NULL,Lex->current_select);
3605
3617
            $6->outer_join|=JOIN_TYPE_LEFT;
3606
3618
            $$=$6;
3607
3619
          }
3614
3626
            /* Change the current name resolution context to a local context. */
3615
3627
            if (push_new_name_resolution_context(YYSession, $1, $5))
3616
3628
              DRIZZLE_YYABORT;
3617
 
            Select->parsing_place= IN_ON;
 
3629
            Lex->current_select->parsing_place= IN_ON;
3618
3630
          }
3619
3631
          expr
3620
3632
          {
3623
3635
              DRIZZLE_YYABORT;
3624
3636
            add_join_on($$, $8);
3625
3637
            Lex->pop_context();
3626
 
            Select->parsing_place= NO_MATTER;
 
3638
            Lex->current_select->parsing_place= NO_MATTER;
3627
3639
          }
3628
3640
        | table_ref RIGHT opt_outer JOIN_SYM table_factor
3629
3641
          {
3634
3646
            LEX *lex= Lex;
3635
3647
            if (!($$= lex->current_select->convert_right_join()))
3636
3648
              DRIZZLE_YYABORT;
3637
 
            add_join_natural($$,$5,$9,Select);
 
3649
            add_join_natural($$,$5,$9,Lex->current_select);
3638
3650
          }
3639
3651
        | table_ref NATURAL RIGHT opt_outer JOIN_SYM table_factor
3640
3652
          {
3641
3653
            DRIZZLE_YYABORT_UNLESS($1 && $6);
3642
 
            add_join_natural($6,$1,NULL,Select);
 
3654
            add_join_natural($6,$1,NULL,Lex->current_select);
3643
3655
            LEX *lex= Lex;
3644
3656
            if (!($$= lex->current_select->convert_right_join()))
3645
3657
              DRIZZLE_YYABORT;
3662
3674
/* Warning - may return NULL in case of incomplete SELECT */
3663
3675
table_factor:
3664
3676
          {
3665
 
            Select_Lex *sel= Select;
 
3677
            Select_Lex *sel= Lex->current_select;
3666
3678
            sel->table_join_options= 0;
3667
3679
          }
3668
3680
          table_ident opt_table_alias opt_key_definition
3669
3681
          {
3670
 
            if (!($$= Select->add_table_to_list(YYSession, $2, $3,
3671
 
                                                Select->get_table_join_options(),
3672
 
                                                Lex->lock_option,
3673
 
                                                Select->pop_index_hints())))
 
3682
            if (!($$= Lex->current_select->add_table_to_list(YYSession, $2, $3,
 
3683
                             Lex->current_select->get_table_join_options(),
 
3684
                             Lex->lock_option,
 
3685
                             Lex->current_select->pop_index_hints())))
3674
3686
              DRIZZLE_YYABORT;
3675
 
            Select->add_joined_table($$);
 
3687
            Lex->current_select->add_joined_table($$);
3676
3688
          }
3677
3689
        | select_derived_init get_select_lex select_derived2
3678
3690
          {
3806
3818
          }
3807
3819
          select_options select_item_list
3808
3820
          {
3809
 
            Select->parsing_place= NO_MATTER;
 
3821
            Lex->current_select->parsing_place= NO_MATTER;
3810
3822
          }
3811
3823
          opt_select_from select_lock_type
3812
3824
        ;
3853
3865
          }
3854
3866
          select_options select_item_list
3855
3867
          {
3856
 
            Select->parsing_place= NO_MATTER;
 
3868
            Lex->current_select->parsing_place= NO_MATTER;
3857
3869
          }
3858
3870
          opt_select_from
3859
3871
        ;
3860
3872
 
3861
3873
get_select_lex:
3862
 
          /* Empty */ { $$= Select; }
 
3874
          /* Empty */ { $$= Lex->current_select; }
3863
3875
        ;
3864
3876
 
3865
3877
select_derived_init:
3875
3887
              my_parse_error(ER(ER_SYNTAX_ERROR));
3876
3888
              DRIZZLE_YYABORT;
3877
3889
            }
3878
 
            embedding= Select->embedding;
 
3890
            embedding= Lex->current_select->embedding;
3879
3891
            $$= embedding &&
3880
3892
                !embedding->nested_join->join_list.elements;
3881
3893
            /* return true if we are deeply nested */
3905
3917
index_hint_definition:
3906
3918
          index_hint_type key_or_index index_hint_clause
3907
3919
          {
3908
 
            Select->set_index_hint_type($1, $3);
 
3920
            Lex->current_select->set_index_hint_type($1, $3);
3909
3921
          }
3910
3922
          '(' key_usage_list ')'
3911
3923
        | USE_SYM key_or_index index_hint_clause
3912
3924
          {
3913
 
            Select->set_index_hint_type(INDEX_HINT_USE, $3);
 
3925
            Lex->current_select->set_index_hint_type(INDEX_HINT_USE, $3);
3914
3926
          }
3915
3927
          '(' opt_key_usage_list ')'
3916
3928
       ;
3922
3934
 
3923
3935
opt_index_hints_list:
3924
3936
          /* empty */
3925
 
        | { Select->alloc_index_hints(YYSession); } index_hints_list
 
3937
        | { Lex->current_select->alloc_index_hints(YYSession); } index_hints_list
3926
3938
        ;
3927
3939
 
3928
3940
opt_key_definition:
3929
 
          {  Select->clear_index_hints(); }
 
3941
          {  Lex->current_select->clear_index_hints(); }
3930
3942
          opt_index_hints_list
3931
3943
        ;
3932
3944
 
3933
3945
opt_key_usage_list:
3934
 
          /* empty */ { Select->add_index_hint(YYSession, NULL, 0); }
 
3946
          /* empty */ { Lex->current_select->add_index_hint(YYSession, NULL, 0); }
3935
3947
        | key_usage_list {}
3936
3948
        ;
3937
3949
 
3938
3950
key_usage_element:
3939
3951
          ident
3940
 
          { Select->add_index_hint(YYSession, $1.str, $1.length); }
 
3952
          { Lex->current_select->add_index_hint(YYSession, $1.str, $1.length); }
3941
3953
        | PRIMARY_SYM
3942
 
          { Select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
 
3954
          { Lex->current_select->add_index_hint(YYSession, (char *)"PRIMARY", 7); }
3943
3955
        ;
3944
3956
 
3945
3957
key_usage_list:
4029
4041
        ;
4030
4042
 
4031
4043
where_clause:
4032
 
          /* empty */  { Select->where= 0; }
 
4044
          /* empty */  { Lex->current_select->where= 0; }
4033
4045
        | WHERE
4034
4046
          {
4035
 
            Select->parsing_place= IN_WHERE;
 
4047
            Lex->current_select->parsing_place= IN_WHERE;
4036
4048
          }
4037
4049
          expr
4038
4050
          {
4039
 
            Select_Lex *select= Select;
 
4051
            Select_Lex *select= Lex->current_select;
4040
4052
            select->where= $3;
4041
4053
            select->parsing_place= NO_MATTER;
4042
4054
            if ($3)
4048
4060
          /* empty */
4049
4061
        | HAVING
4050
4062
          {
4051
 
            Select->parsing_place= IN_HAVING;
 
4063
            Lex->current_select->parsing_place= IN_HAVING;
4052
4064
          }
4053
4065
          expr
4054
4066
          {
4055
 
            Select_Lex *sel= Select;
 
4067
            Select_Lex *sel= Lex->current_select;
4056
4068
            sel->having= $3;
4057
4069
            sel->parsing_place= NO_MATTER;
4058
4070
            if ($3)
4214
4226
limit_options:
4215
4227
          limit_option
4216
4228
          {
4217
 
            Select_Lex *sel= Select;
 
4229
            Select_Lex *sel= Lex->current_select;
4218
4230
            sel->select_limit= $1;
4219
4231
            sel->offset_limit= 0;
4220
4232
            sel->explicit_limit= 1;
4221
4233
          }
4222
4234
        | limit_option ',' limit_option
4223
4235
          {
4224
 
            Select_Lex *sel= Select;
 
4236
            Select_Lex *sel= Lex->current_select;
4225
4237
            sel->select_limit= $3;
4226
4238
            sel->offset_limit= $1;
4227
4239
            sel->explicit_limit= 1;
4228
4240
          }
4229
4241
        | limit_option OFFSET_SYM limit_option
4230
4242
          {
4231
 
            Select_Lex *sel= Select;
 
4243
            Select_Lex *sel= Lex->current_select;
4232
4244
            sel->select_limit= $1;
4233
4245
            sel->offset_limit= $3;
4234
4246
            sel->explicit_limit= 1;
4249
4261
          }
4250
4262
        | LIMIT limit_option
4251
4263
          {
4252
 
            Select_Lex *sel= Select;
 
4264
            Select_Lex *sel= Lex->current_select;
4253
4265
            sel->select_limit= $2;
4254
4266
            sel->explicit_limit= 1;
4255
4267
          }
4395
4407
table_name:
4396
4408
          table_ident
4397
4409
          {
4398
 
            if (!Select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
 
4410
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL, TL_OPTION_UPDATING))
4399
4411
              DRIZZLE_YYABORT;
4400
4412
          }
4401
4413
        ;
4408
4420
table_alias_ref:
4409
4421
          table_ident
4410
4422
          {
4411
 
            if (!Select->add_table_to_list(YYSession, $1, NULL,
 
4423
            if (!Lex->current_select->add_table_to_list(YYSession, $1, NULL,
4412
4424
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4413
4425
                                           Lex->lock_option ))
4414
4426
              DRIZZLE_YYABORT;
4440
4452
          }
4441
4453
          opt_ignore insert2
4442
4454
          {
4443
 
            Select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
 
4455
            Lex->current_select->set_lock_for_tables(TL_WRITE_CONCURRENT_INSERT);
4444
4456
            Lex->current_select= &Lex->select_lex;
4445
4457
          }
4446
4458
          insert_field_spec opt_insert_update
4457
4469
          }
4458
4470
          insert2
4459
4471
          {
4460
 
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4472
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4461
4473
            Lex->current_select= &Lex->select_lex;
4462
4474
          }
4463
4475
          insert_field_spec
4501
4513
          VALUES values_list {}
4502
4514
        | VALUE_SYM values_list {}
4503
4515
        | create_select
4504
 
          { Select->set_braces(0);}
 
4516
          { Lex->current_select->set_braces(0);}
4505
4517
          union_clause {}
4506
4518
        | '(' create_select ')'
4507
 
          { Select->set_braces(1);}
 
4519
          { Lex->current_select->set_braces(1);}
4508
4520
          union_opt {}
4509
4521
        ;
4510
4522
 
4610
4622
              be too pessimistic. We will decrease lock level if possible in
4611
4623
              mysql_multi_update().
4612
4624
            */
4613
 
            Select->set_lock_for_tables(TL_WRITE_DEFAULT);
 
4625
            Lex->current_select->set_lock_for_tables(TL_WRITE_DEFAULT);
4614
4626
          }
4615
4627
          where_clause opt_order_clause delete_limit_clause {}
4616
4628
        ;
4661
4673
single_multi:
4662
4674
          FROM table_ident
4663
4675
          {
4664
 
            if (!Select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
 
4676
            if (!Lex->current_select->add_table_to_list(YYSession, $2, NULL, TL_OPTION_UPDATING,
4665
4677
                                           Lex->lock_option))
4666
4678
              DRIZZLE_YYABORT;
4667
4679
          }
4691
4703
table_wild_one:
4692
4704
          ident opt_wild
4693
4705
          {
4694
 
            if (!Select->add_table_to_list(YYSession, new Table_ident($1),
4695
 
                                           NULL,
4696
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4697
 
                                           Lex->lock_option))
 
4706
            if (!Lex->current_select->add_table_to_list(YYSession,
 
4707
                    new Table_ident($1), NULL,
 
4708
                    TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4709
                    Lex->lock_option))
4698
4710
              DRIZZLE_YYABORT;
4699
4711
          }
4700
4712
        | ident '.' ident opt_wild
4701
4713
          {
4702
 
            if (!Select->add_table_to_list(YYSession,
4703
 
                                           new Table_ident(YYSession, $1, $3, 0),
4704
 
                                           NULL,
4705
 
                                           TL_OPTION_UPDATING | TL_OPTION_ALIAS,
4706
 
                                           Lex->lock_option))
 
4714
            if (!Lex->current_select->add_table_to_list(YYSession,
 
4715
                    new Table_ident(YYSession, $1, $3, 0), NULL,
 
4716
                    TL_OPTION_UPDATING | TL_OPTION_ALIAS,
 
4717
                    Lex->lock_option))
4707
4718
              DRIZZLE_YYABORT;
4708
4719
          }
4709
4720
        ;
4719
4730
        ;
4720
4731
 
4721
4732
opt_delete_option:
4722
 
          QUICK        { Select->options|= OPTION_QUICK; }
 
4733
          QUICK        { Lex->current_select->options|= OPTION_QUICK; }
4723
4734
        | IGNORE_SYM   { Lex->ignore= 1; }
4724
4735
        ;
4725
4736
 
4759
4770
           {
4760
4771
             LEX *lex= Lex;
4761
4772
             lex->sql_command= SQLCOM_SHOW_DATABASES;
 
4773
             lex->command=
 
4774
               new(std::nothrow) command::Select(SQLCOM_SHOW_DATABASES, 
 
4775
                                                 YYSession);
 
4776
             if (lex->command == NULL)
 
4777
               DRIZZLE_YYABORT;
4762
4778
             if (prepare_schema_table(YYSession, lex, 0, "SCHEMATA"))
4763
4779
               DRIZZLE_YYABORT;
4764
4780
           }
4766
4782
           {
4767
4783
             LEX *lex= Lex;
4768
4784
             lex->sql_command= SQLCOM_SHOW_TABLES;
 
4785
             lex->command=
 
4786
               new(std::nothrow) command::Select(SQLCOM_SHOW_TABLES,
 
4787
                                                 YYSession);
 
4788
             if (lex->command == NULL)
 
4789
               DRIZZLE_YYABORT;
4769
4790
             lex->select_lex.db= $3;
4770
4791
             if (prepare_schema_table(YYSession, lex, 0, "TABLE_NAMES"))
4771
4792
               DRIZZLE_YYABORT;
4774
4795
           {
4775
4796
             LEX *lex= Lex;
4776
4797
             lex->sql_command= SQLCOM_SHOW_TABLE_STATUS;
 
4798
             lex->command=
 
4799
               new(std::nothrow) command::Select(SQLCOM_SHOW_TABLE_STATUS,
 
4800
                                                 YYSession);
 
4801
             if (lex->command == NULL)
 
4802
               DRIZZLE_YYABORT;
4777
4803
             lex->select_lex.db= $3;
4778
4804
             if (prepare_schema_table(YYSession, lex, 0, "TABLES"))
4779
4805
               DRIZZLE_YYABORT;
4782
4808
          {
4783
4809
            LEX *lex= Lex;
4784
4810
            lex->sql_command= SQLCOM_SHOW_OPEN_TABLES;
 
4811
            lex->command=
 
4812
              new(std::nothrow) command::Select(SQLCOM_SHOW_OPEN_TABLES,
 
4813
                                                YYSession);
 
4814
            if (lex->command == NULL)
 
4815
              DRIZZLE_YYABORT;
4785
4816
            lex->select_lex.db= $3;
4786
4817
            if (prepare_schema_table(YYSession, lex, 0, "OPEN_TABLES"))
4787
4818
              DRIZZLE_YYABORT;
4795
4826
          {
4796
4827
            LEX *lex= Lex;
4797
4828
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4829
            lex->command=
 
4830
              new(std::nothrow) command::Select(SQLCOM_SHOW_FIELDS, YYSession);
 
4831
            if (lex->command == NULL)
 
4832
              DRIZZLE_YYABORT;
4798
4833
            if ($5)
4799
4834
              $4->change_db($5);
4800
4835
            if (prepare_schema_table(YYSession, lex, $4, "COLUMNS"))
4804
4839
          {
4805
4840
            LEX *lex= Lex;
4806
4841
            lex->sql_command= SQLCOM_SHOW_KEYS;
 
4842
            lex->command= new(std::nothrow) command::Select(SQLCOM_SHOW_KEYS,
 
4843
                                                            YYSession);
 
4844
            if (lex->command == NULL)
 
4845
              DRIZZLE_YYABORT;
4807
4846
            if ($4)
4808
4847
              $3->change_db($4);
4809
4848
            if (prepare_schema_table(YYSession, lex, $3, "STATISTICS"))
4810
4849
              DRIZZLE_YYABORT;
4811
4850
          }
4812
4851
        | COUNT_SYM '(' '*' ')' WARNINGS
4813
 
          { (void) create_select_for_variable("warning_count"); }
 
4852
          { 
 
4853
            (void) create_select_for_variable("warning_count"); 
 
4854
            LEX *lex= Lex;
 
4855
            lex->command= new(std::nothrow) command::Select(SQLCOM_SELECT,
 
4856
                                                            YYSession);
 
4857
            if (lex->command == NULL)
 
4858
              DRIZZLE_YYABORT;
 
4859
          }
4814
4860
        | COUNT_SYM '(' '*' ')' ERRORS
4815
 
          { (void) create_select_for_variable("error_count"); }
 
4861
          { 
 
4862
            (void) create_select_for_variable("error_count"); 
 
4863
            LEX *lex= Lex;
 
4864
            lex->command= new(std::nothrow) command::Select(SQLCOM_SELECT,
 
4865
                                                            YYSession);
 
4866
            if (lex->command == NULL)
 
4867
              DRIZZLE_YYABORT;
 
4868
          }
4816
4869
        | WARNINGS opt_limit_clause_init
4817
4870
          { Lex->sql_command = SQLCOM_SHOW_WARNS;}
4818
4871
        | ERRORS opt_limit_clause_init
4821
4874
          {
4822
4875
            LEX *lex= Lex;
4823
4876
            lex->sql_command= SQLCOM_SHOW_STATUS;
 
4877
            lex->command=
 
4878
              new(std::nothrow) command::ShowStatus(SQLCOM_SHOW_STATUS,
 
4879
                                                    YYSession,
 
4880
                                                    &LOCK_status);
 
4881
            if (lex->command == NULL)
 
4882
              DRIZZLE_YYABORT;
4824
4883
            lex->option_type= $1;
4825
4884
            if (prepare_schema_table(YYSession, lex, 0, "STATUS"))
4826
4885
              DRIZZLE_YYABORT;
4831
4890
          {
4832
4891
            LEX *lex= Lex;
4833
4892
            lex->sql_command= SQLCOM_SHOW_VARIABLES;
 
4893
            lex->command=
 
4894
              new(std::nothrow) command::Select(SQLCOM_SHOW_VARIABLES, 
 
4895
                                                YYSession);
 
4896
            if (lex->command == NULL)
 
4897
              DRIZZLE_YYABORT;
4834
4898
            lex->option_type= $1;
4835
4899
            if (prepare_schema_table(YYSession, lex, 0, "VARIABLES"))
4836
4900
              DRIZZLE_YYABORT;
4875
4939
          }
4876
4940
        | WHERE expr
4877
4941
          {
4878
 
            Select->where= $2;
 
4942
            Lex->current_select->where= $2;
4879
4943
            if ($2)
4880
4944
              $2->top_level_item();
4881
4945
          }
4890
4954
            mysql_init_select(lex);
4891
4955
            lex->current_select->parsing_place= SELECT_LIST;
4892
4956
            lex->sql_command= SQLCOM_SHOW_FIELDS;
 
4957
            lex->command= new(std::nothrow) command::Select(SQLCOM_SHOW_FIELDS,
 
4958
                                                            YYSession);
 
4959
            if (lex->command == NULL)
 
4960
              DRIZZLE_YYABORT;
4893
4961
            lex->select_lex.db= 0;
4894
4962
            lex->verbose= 0;
4895
4963
            if (prepare_schema_table(YYSession, lex, $2, "COLUMNS"))
5022
5090
          TABLE_SYM table_ident
5023
5091
          {
5024
5092
            LEX *lex=Lex;
5025
 
            if (!Select->add_table_to_list(YYSession, $12, NULL, TL_OPTION_UPDATING,
5026
 
                                           lex->lock_option))
 
5093
            if (!Lex->current_select->add_table_to_list(YYSession,
 
5094
                    $12, NULL, TL_OPTION_UPDATING,
 
5095
                    lex->lock_option))
5027
5096
              DRIZZLE_YYABORT;
5028
5097
            lex->field_list.empty();
5029
5098
            lex->update_list.empty();
5260
5329
table_wild:
5261
5330
          ident '.' '*'
5262
5331
          {
5263
 
            Select_Lex *sel= Select;
 
5332
            Select_Lex *sel= Lex->current_select;
5264
5333
            $$ = new Item_field(Lex->current_context(), NULL, $1.str, "*");
5265
5334
            sel->with_wild++;
5266
5335
          }
5267
5336
        | ident '.' ident '.' '*'
5268
5337
          {
5269
 
            Select_Lex *sel= Select;
 
5338
            Select_Lex *sel= Lex->current_select;
5270
5339
            $$ = new Item_field(Lex->current_context(), (YYSession->client_capabilities &
5271
5340
                                CLIENT_NO_SCHEMA ? NULL : $1.str),
5272
5341
                                $3.str,"*");
5282
5351
          ident
5283
5352
          {
5284
5353
            {
5285
 
              Select_Lex *sel=Select;
 
5354
              Select_Lex *sel=Lex->current_select;
5286
5355
              $$= (sel->parsing_place != IN_HAVING ||
5287
5356
                  sel->get_in_sum_expr() > 0) ?
5288
5357
                  (Item*) new Item_field(Lex->current_context(),
5297
5366
simple_ident_nospvar:
5298
5367
          ident
5299
5368
          {
5300
 
            Select_Lex *sel=Select;
 
5369
            Select_Lex *sel=Lex->current_select;
5301
5370
            $$= (sel->parsing_place != IN_HAVING ||
5302
5371
                sel->get_in_sum_expr() > 0) ?
5303
5372
                (Item*) new Item_field(Lex->current_context(),
5372
5441
          ident { $$=$1;}
5373
5442
        | ident '.' ident '.' ident
5374
5443
          {
5375
 
            TableList *table= (TableList*) Select->table_list.first;
 
5444
            TableList *table=
 
5445
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5376
5446
            if (my_strcasecmp(table_alias_charset, $1.str, table->db))
5377
5447
            {
5378
5448
              my_error(ER_WRONG_DB_NAME, MYF(0), $1.str);
5388
5458
          }
5389
5459
        | ident '.' ident
5390
5460
          {
5391
 
            TableList *table= (TableList*) Select->table_list.first;
 
5461
            TableList *table=
 
5462
              reinterpret_cast<TableList*>(Lex->current_select->table_list.first);
5392
5463
            if (my_strcasecmp(table_alias_charset, $1.str, table->alias))
5393
5464
            {
5394
5465
              my_error(ER_WRONG_TABLE_NAME, MYF(0), $1.str);