~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/sql_parse.cc

  • Committer: Mark Atwood
  • Date: 2008-10-16 11:33:16 UTC
  • mto: (520.1.13 drizzle)
  • mto: This revision was merged to the branch mainline in revision 530.
  • Revision ID: mark@fallenpegasus.com-20081016113316-ff6jdt31ck90sjdh
an implemention of the errmsg plugin

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
#include <drizzled/server_includes.h>
18
18
#include "sql_repl.h"
19
19
#include "rpl_filter.h"
20
 
#include "repl_failsafe.h"
21
20
#include "logging.h"
22
21
#include <drizzled/drizzled_error_messages.h>
23
22
 
70
69
 
71
70
bool end_active_trans(THD *thd)
72
71
{
73
 
  int error=0;
74
 
  if (unlikely(thd->in_sub_stmt))
75
 
  {
76
 
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
77
 
    return(1);
78
 
  }
 
72
  int error= 0;
 
73
 
79
74
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
80
75
  {
81
76
    my_error(ER_XAER_RMFAIL, MYF(0),
100
95
 
101
96
bool begin_trans(THD *thd)
102
97
{
103
 
  int error=0;
104
 
  if (unlikely(thd->in_sub_stmt))
105
 
  {
106
 
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
107
 
    return 1;
108
 
  }
 
98
  int error= 0;
109
99
  if (thd->locked_tables)
110
100
  {
111
101
    thd->lock=thd->locked_tables;
193
183
  sql_command_flags[SQLCOM_SHOW_FIELDS]=      CF_STATUS_COMMAND;
194
184
  sql_command_flags[SQLCOM_SHOW_KEYS]=        CF_STATUS_COMMAND;
195
185
  sql_command_flags[SQLCOM_SHOW_VARIABLES]=   CF_STATUS_COMMAND;
196
 
  sql_command_flags[SQLCOM_SHOW_CHARSETS]=    CF_STATUS_COMMAND;
197
 
  sql_command_flags[SQLCOM_SHOW_COLLATIONS]=  CF_STATUS_COMMAND;
198
186
  sql_command_flags[SQLCOM_SHOW_BINLOGS]= CF_STATUS_COMMAND;
199
 
  sql_command_flags[SQLCOM_SHOW_SLAVE_HOSTS]= CF_STATUS_COMMAND;
200
 
  sql_command_flags[SQLCOM_SHOW_BINLOG_EVENTS]= CF_STATUS_COMMAND;
201
187
  sql_command_flags[SQLCOM_SHOW_WARNS]= CF_STATUS_COMMAND;
202
188
  sql_command_flags[SQLCOM_SHOW_ERRORS]= CF_STATUS_COMMAND;
203
189
  sql_command_flags[SQLCOM_SHOW_ENGINE_STATUS]= CF_STATUS_COMMAND;
233
219
  Vio* save_vio;
234
220
  ulong save_client_capabilities;
235
221
 
236
 
  thd_proc_info(thd, "Execution of init_command");
 
222
  thd->set_proc_info("Execution of init_command");
237
223
  /*
238
224
    We need to lock init_command_var because
239
225
    during execution of init_command_var query
271
257
  bool do_release= 0;
272
258
  int res= 0;
273
259
 
274
 
  if (unlikely(thd->in_sub_stmt))
275
 
  {
276
 
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
277
 
    return(1);
278
 
  }
279
260
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
280
261
  {
281
262
    my_error(ER_XAER_RMFAIL, MYF(0),
514
495
  bool error= 0;
515
496
 
516
497
  thd->command=command;
517
 
  /*
518
 
    Commands which always take a long time are logged into
519
 
    the slow log only if opt_log_slow_admin_statements is set.
520
 
  */
521
 
  thd->enable_slow_log= true;
522
498
  thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
523
499
  thd->set_time();
524
500
  pthread_mutex_lock(&LOCK_thread_count);
555
531
    }
556
532
    break;
557
533
  }
558
 
  case COM_REGISTER_SLAVE:
559
 
  {
560
 
    if (!register_slave(thd, (unsigned char*)packet, packet_length))
561
 
      my_ok(thd);
562
 
    break;
563
 
  }
564
534
  case COM_CHANGE_USER:
565
535
  {
566
536
    status_var_increment(thd->status_var.com_other);
783
753
      uint32_t slave_server_id;
784
754
 
785
755
      status_var_increment(thd->status_var.com_other);
786
 
      thd->enable_slow_log= opt_log_slow_admin_statements;
787
756
      /* TODO: The following has to be changed to an 8 byte integer */
788
757
      pos = uint4korr(packet);
789
758
      flags = uint2korr(packet + 4);
793
762
      thd->server_id = slave_server_id;
794
763
 
795
764
      mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
796
 
      unregister_slave(thd,1,1);
797
765
      /*  fake COM_QUIT -- if we get here, the thread needs to terminate */
798
766
      error = true;
799
767
      break;
879
847
 
880
848
  log_slow_statement(thd);
881
849
 
882
 
  thd_proc_info(thd, "cleaning up");
 
850
  thd->set_proc_info("cleaning up");
883
851
  pthread_mutex_lock(&LOCK_thread_count); // For process list
884
 
  thd_proc_info(thd, 0);
 
852
  thd->set_proc_info(0);
885
853
  thd->command=COM_SLEEP;
886
854
  thd->query=0;
887
855
  thd->query_length=0;
895
863
 
896
864
void log_slow_statement(THD *thd)
897
865
{
898
 
  /*
899
 
    The following should never be true with our current code base,
900
 
    but better to keep this here so we don't accidently try to log a
901
 
    statement in a trigger or stored function
902
 
  */
903
 
  if (unlikely(thd->in_sub_stmt))
904
 
    return;                           // Don't set time for sub stmt
905
 
 
906
866
  logging_post_do(thd);
907
867
 
908
868
  return;
1234
1194
  case SQLCOM_SHOW_FIELDS:
1235
1195
  case SQLCOM_SHOW_KEYS:
1236
1196
  case SQLCOM_SHOW_VARIABLES:
1237
 
  case SQLCOM_SHOW_CHARSETS:
1238
 
  case SQLCOM_SHOW_COLLATIONS:
1239
1197
  case SQLCOM_SELECT:
1240
1198
  {
1241
1199
    thd->status_var.last_query_cost= 0.0;
1287
1245
                              (1L << (uint32_t) DRIZZLE_ERROR::WARN_LEVEL_ERROR));
1288
1246
    break;
1289
1247
  }
1290
 
  case SQLCOM_SHOW_SLAVE_HOSTS:
1291
 
  {
1292
 
    res = show_slave_hosts(thd);
1293
 
    break;
1294
 
  }
1295
 
  case SQLCOM_SHOW_BINLOG_EVENTS:
1296
 
  {
1297
 
    res = mysql_show_binlog_events(thd);
1298
 
    break;
1299
 
  }
1300
 
 
1301
1248
  case SQLCOM_ASSIGN_TO_KEYCACHE:
1302
1249
  {
1303
1250
    assert(first_table == all_tables && first_table != 0);
1523
1470
    assert(first_table == all_tables && first_table != 0);
1524
1471
    if (end_active_trans(thd))
1525
1472
      goto error;
1526
 
    /*
1527
 
      Currently CREATE INDEX or DROP INDEX cause a full table rebuild
1528
 
      and thus classify as slow administrative statements just like
1529
 
      ALTER TABLE.
1530
 
    */
1531
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1532
1473
 
1533
1474
    memset(&create_info, 0, sizeof(create_info));
1534
1475
    create_info.db_type= 0;
1620
1561
        break;
1621
1562
      }
1622
1563
 
1623
 
      thd->enable_slow_log= opt_log_slow_admin_statements;
1624
1564
      res= mysql_alter_table(thd, select_lex->db, lex->name.str,
1625
1565
                             &create_info,
1626
1566
                             first_table,
1671
1611
  case SQLCOM_REPAIR:
1672
1612
  {
1673
1613
    assert(first_table == all_tables && first_table != 0);
1674
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1675
1614
    res= mysql_repair_table(thd, first_table, &lex->check_opt);
1676
1615
    /* ! we write after unlocking the table */
1677
1616
    /*
1685
1624
  case SQLCOM_CHECK:
1686
1625
  {
1687
1626
    assert(first_table == all_tables && first_table != 0);
1688
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1689
1627
    res = mysql_check_table(thd, first_table, &lex->check_opt);
1690
1628
    select_lex->table_list.first= (unsigned char*) first_table;
1691
1629
    lex->query_tables=all_tables;
1694
1632
  case SQLCOM_ANALYZE:
1695
1633
  {
1696
1634
    assert(first_table == all_tables && first_table != 0);
1697
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1698
1635
    res= mysql_analyze_table(thd, first_table, &lex->check_opt);
1699
1636
    /* ! we write after unlocking the table */
1700
1637
    write_bin_log(thd, true, thd->query, thd->query_length);
1706
1643
  case SQLCOM_OPTIMIZE:
1707
1644
  {
1708
1645
    assert(first_table == all_tables && first_table != 0);
1709
 
    thd->enable_slow_log= opt_log_slow_admin_statements;
1710
1646
    res= mysql_optimize_table(thd, first_table, &lex->check_opt);
1711
1647
    /* ! we write after unlocking the table */
1712
1648
    write_bin_log(thd, true, thd->query, thd->query_length);
1929
1865
    if (add_item_to_list(thd, new Item_null()))
1930
1866
      goto error;
1931
1867
 
1932
 
    thd_proc_info(thd, "init");
 
1868
    thd->set_proc_info("init");
1933
1869
    if ((res= open_and_lock_tables(thd, all_tables)))
1934
1870
      break;
1935
1871
 
2380
2316
    break;
2381
2317
  }
2382
2318
  case SQLCOM_SAVEPOINT:
2383
 
    if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN) ||
2384
 
          thd->in_sub_stmt) || !opt_using_transactions)
 
2319
    if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)) || !opt_using_transactions)
2385
2320
      my_ok(thd);
2386
2321
    else
2387
2322
    {
2433
2368
    my_ok(thd);
2434
2369
    break;
2435
2370
  }
2436
 
  thd_proc_info(thd, "query end");
 
2371
  thd->set_proc_info("query end");
2437
2372
 
2438
2373
  /*
2439
2374
    Binlog-related cleanup:
2608
2543
 
2609
2544
void mysql_reset_thd_for_next_command(THD *thd)
2610
2545
{
2611
 
  assert(! thd->in_sub_stmt);
2612
2546
  thd->free_list= 0;
2613
2547
  thd->select_number= 1;
2614
2548
  /*
2863
2797
      assert(thd->is_error());
2864
2798
    }
2865
2799
    lex->unit.cleanup();
2866
 
    thd_proc_info(thd, "freeing items");
 
2800
    thd->set_proc_info("freeing items");
2867
2801
    thd->end_statement();
2868
2802
    thd->cleanup_after_query();
2869
2803
    assert(thd->change_list.is_empty());
2916
2850
                       Item *default_value, Item *on_update_value,
2917
2851
                       LEX_STRING *comment,
2918
2852
                       char *change,
2919
 
                       List<String> *interval_list, const CHARSET_INFO * const cs)
 
2853
                       List<String> *interval_list, const CHARSET_INFO * const cs,
 
2854
                       virtual_column_info *vcol_info)
2920
2855
{
2921
2856
  register Create_field *new_field;
2922
2857
  LEX  *lex= thd->lex;
2987
2922
  if (!(new_field= new Create_field()) ||
2988
2923
      new_field->init(thd, field_name->str, type, length, decimals, type_modifier,
2989
2924
                      default_value, on_update_value, comment, change,
2990
 
                      interval_list, cs, 0, column_format))
 
2925
                      interval_list, cs, 0, column_format,
 
2926
                      vcol_info))
2991
2927
    return(1);
2992
2928
 
2993
2929
  lex->alter_info.create_list.push_back(new_field);
3629
3565
  select_errors=0;                              /* Write if more errors */
3630
3566
  bool tmp_write_to_binlog= 1;
3631
3567
 
3632
 
  assert(!thd || !thd->in_sub_stmt);
3633
 
 
3634
3568
  if (options & REFRESH_LOG)
3635
3569
  {
3636
3570
    /*