~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_parse.cc

Merging trunk changes from over weekend.

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
bool end_active_trans(THD *thd)
84
84
{
85
85
  int error=0;
 
86
  DBUG_ENTER("end_active_trans");
86
87
  if (unlikely(thd->in_sub_stmt))
87
88
  {
88
89
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
89
 
    return(1);
 
90
    DBUG_RETURN(1);
90
91
  }
91
92
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
92
93
  {
93
94
    my_error(ER_XAER_RMFAIL, MYF(0),
94
95
             xa_state_names[thd->transaction.xid_state.xa_state]);
95
 
    return(1);
 
96
    DBUG_RETURN(1);
96
97
  }
97
98
  if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
98
99
                      OPTION_TABLE_LOCK))
99
100
  {
 
101
    DBUG_PRINT("info",("options: 0x%llx", thd->options));
100
102
    /* Safety if one did "drop table" on locked tables */
101
103
    if (!thd->locked_tables)
102
104
      thd->options&= ~OPTION_TABLE_LOCK;
105
107
      error=1;
106
108
  }
107
109
  thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
108
 
  thd->transaction.all.modified_non_trans_table= FALSE;
109
 
  return(error);
 
110
  thd->transaction.all.modified_non_trans_table= false;
 
111
  DBUG_RETURN(error);
110
112
}
111
113
 
112
114
 
290
292
    thd->fatal_error();
291
293
    goto end;
292
294
  }
 
295
  DBUG_ENTER("handle_bootstrap");
293
296
 
294
297
  pthread_detach_this_thread();
295
298
  thd->thread_stack= (char*) &thd;
349
352
    thd->query= (char*) thd->memdup_w_gap(buff, length+1, 
350
353
                                          thd->db_length+1);
351
354
    thd->query[length] = '\0';
 
355
    DBUG_PRINT("query",("%-.4096s",thd->query));
352
356
 
353
357
    /*
354
358
      We don't need to obtain LOCK_thread_count here because in bootstrap
380
384
  (void) pthread_cond_broadcast(&COND_thread_count);
381
385
  my_thread_end();
382
386
  pthread_exit(0);
383
 
  return(0);
 
387
  DBUG_RETURN(0);
384
388
}
385
389
 
386
390
/* This works because items are allocated with sql_alloc() */
388
392
void free_items(Item *item)
389
393
{
390
394
  Item *next;
 
395
  DBUG_ENTER("free_items");
391
396
  for (; item ; item=next)
392
397
  {
393
398
    next=item->next;
394
399
    item->delete_self();
395
400
  }
396
 
  return;
 
401
  DBUG_VOID_RETURN;
397
402
}
398
403
 
399
404
/* This works because items are allocated with sql_alloc() */
400
405
 
401
406
void cleanup_items(Item *item)
402
407
{
 
408
  DBUG_ENTER("cleanup_items");
403
409
  for (; item ; item=item->next)
404
410
    item->cleanup();
405
 
  return;
 
411
  DBUG_VOID_RETURN;
406
412
}
407
413
 
408
414
/**
419
425
{
420
426
  bool do_release= 0;
421
427
  int res= 0;
 
428
  DBUG_ENTER("end_trans");
422
429
 
423
430
  if (unlikely(thd->in_sub_stmt))
424
431
  {
425
432
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
426
 
    return(1);
 
433
    DBUG_RETURN(1);
427
434
  }
428
435
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
429
436
  {
430
437
    my_error(ER_XAER_RMFAIL, MYF(0),
431
438
             xa_state_names[thd->transaction.xid_state.xa_state]);
432
 
    return(1);
 
439
    DBUG_RETURN(1);
433
440
  }
434
441
  switch (completion) {
435
442
  case COMMIT:
441
448
    thd->server_status&= ~SERVER_STATUS_IN_TRANS;
442
449
    res= ha_commit(thd);
443
450
    thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
444
 
    thd->transaction.all.modified_non_trans_table= FALSE;
 
451
    thd->transaction.all.modified_non_trans_table= false;
445
452
    break;
446
453
  case COMMIT_RELEASE:
447
454
    do_release= 1; /* fall through */
459
466
    if (ha_rollback(thd))
460
467
      res= -1;
461
468
    thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
462
 
    thd->transaction.all.modified_non_trans_table= FALSE;
 
469
    thd->transaction.all.modified_non_trans_table= false;
463
470
    if (!res && (completion == ROLLBACK_AND_CHAIN))
464
471
      res= begin_trans(thd);
465
472
    break;
467
474
  default:
468
475
    res= -1;
469
476
    my_error(ER_UNKNOWN_COM_ERROR, MYF(0));
470
 
    return(-1);
 
477
    DBUG_RETURN(-1);
471
478
  }
472
479
 
473
480
  if (res < 0)
475
482
  else if ((res == 0) && do_release)
476
483
    thd->killed= THD::KILL_CONNECTION;
477
484
 
478
 
  return(res);
 
485
  DBUG_RETURN(res);
479
486
}
480
487
 
481
488
 
498
505
  ulong packet_length;
499
506
  NET *net= &thd->net;
500
507
  enum enum_server_command command;
 
508
  DBUG_ENTER("do_command");
501
509
 
502
510
  /*
503
511
    indicator of uninitialized lex => normal flow of errors handling
525
533
  packet_length= my_net_read(net);
526
534
  if (packet_length == packet_error)
527
535
  {
 
536
    DBUG_PRINT("info",("Got error %d reading command from socket %s",
 
537
                       net->error,
 
538
                       vio_description(net->vio)));
528
539
 
529
540
    /* Check if we can continue without closing the connection */
530
541
 
534
545
 
535
546
    if (net->error != 3)
536
547
    {
537
 
      return_value= TRUE;                       // We have to close it.
 
548
      return_value= true;                       // We have to close it.
538
549
      goto out;
539
550
    }
540
551
 
541
552
    net->error= 0;
542
 
    return_value= FALSE;
 
553
    return_value= false;
543
554
    goto out;
544
555
  }
545
556
 
566
577
  if (command >= COM_END)
567
578
    command= COM_END;                           // Wrong command
568
579
 
 
580
  DBUG_PRINT("info",("Command on %s = %d (%s)",
 
581
                     vio_description(net->vio), command,
 
582
                     command_name[command].str));
569
583
 
570
584
  /* Restore read timeout value */
571
585
  my_net_set_read_timeout(net, thd->variables.net_read_timeout);
574
588
  return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1));
575
589
 
576
590
out:
577
 
  return(return_value);
 
591
  DBUG_RETURN(return_value);
578
592
}
579
593
 
580
594
/**
588
602
  @see mysql_execute_command
589
603
 
590
604
  @returns Status code
591
 
    @retval TRUE The statement should be denied.
592
 
    @retval FALSE The statement isn't updating any relevant tables.
 
605
    @retval true The statement should be denied.
 
606
    @retval false The statement isn't updating any relevant tables.
593
607
*/
594
608
 
595
609
static my_bool deny_updates_if_read_only_option(THD *thd,
596
610
                                                TABLE_LIST *all_tables)
597
611
{
 
612
  DBUG_ENTER("deny_updates_if_read_only_option");
598
613
 
599
614
  if (!opt_readonly)
600
 
    return(FALSE);
 
615
    DBUG_RETURN(false);
601
616
 
602
617
  LEX *lex= thd->lex;
603
618
 
604
619
  if (!(sql_command_flags[lex->sql_command] & CF_CHANGES_DATA))
605
 
    return(FALSE);
 
620
    DBUG_RETURN(false);
606
621
 
607
622
  /* Multi update is an exception and is dealt with later. */
608
623
  if (lex->sql_command == SQLCOM_UPDATE_MULTI)
609
 
    return(FALSE);
 
624
    DBUG_RETURN(false);
610
625
 
611
626
  const my_bool create_temp_tables= 
612
627
    (lex->sql_command == SQLCOM_CREATE_TABLE) &&
630
645
      /*
631
646
        An attempt was made to modify one or more non-temporary tables.
632
647
      */
633
 
      return(TRUE);
 
648
      DBUG_RETURN(true);
634
649
  }
635
650
 
636
651
 
637
652
  /* Assuming that only temporary tables are modified. */
638
 
  return(FALSE);
 
653
  DBUG_RETURN(false);
639
654
}
640
655
 
641
656
/**
664
679
{
665
680
  NET *net= &thd->net;
666
681
  bool error= 0;
 
682
  DBUG_ENTER("dispatch_command");
 
683
  DBUG_PRINT("info",("packet: '%*.s'; command: %d", packet_length, packet, command));
667
684
 
668
685
  thd->command=command;
669
686
  /*
670
687
    Commands which always take a long time are logged into
671
688
    the slow log only if opt_log_slow_admin_statements is set.
672
689
  */
673
 
  thd->enable_slow_log= TRUE;
 
690
  thd->enable_slow_log= true;
674
691
  thd->lex->sql_command= SQLCOM_END; /* to avoid confusing VIEW detectors */
675
692
  thd->set_time();
676
693
  VOID(pthread_mutex_lock(&LOCK_thread_count));
706
723
    status_var_increment(thd->status_var.com_stat[SQLCOM_CHANGE_DB]);
707
724
    thd->convert_string(&tmp, system_charset_info,
708
725
                        packet, packet_length, thd->charset());
709
 
    if (!mysql_change_db(thd, &tmp, FALSE))
 
726
    if (!mysql_change_db(thd, &tmp, false))
710
727
    {
711
728
      general_log_write(thd, command, thd->db, thd->db_length);
712
729
      my_ok(thd);
802
819
    /* Clear variables that are allocated */
803
820
    thd->user_connect= 0;
804
821
    thd->security_ctx->priv_user= thd->security_ctx->user;
805
 
    res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, FALSE);
 
822
    res= check_user(thd, COM_CHANGE_USER, passwd, passwd_len, db, false);
806
823
 
807
824
    if (res)
808
825
    {
844
861
    const char* end_of_stmt= NULL;
845
862
 
846
863
    general_log_write(thd, command, thd->query, thd->query_length);
 
864
    DBUG_PRINT("query",("%-.4096s",thd->query));
847
865
 
848
866
    if (!(specialflag & SPECIAL_NO_PRIOR))
849
867
    {
899
917
      tmp_sched_param.sched_priority= WAIT_PRIOR;
900
918
      (void)pthread_setschedparam(pthread_self(), SCHED_OTHER, &tmp_sched_param);
901
919
    }
 
920
    DBUG_PRINT("info",("query ready"));
902
921
    break;
903
922
  }
904
923
  case COM_FIELD_LIST:                          // This isn't actually needed
962
981
    general_log_print(thd, command, NullS);
963
982
    net->error=0;                               // Don't give 'abort' message
964
983
    thd->main_da.disable_status();              // Don't send anything back
965
 
    error=TRUE;                                 // End server
 
984
    error=true;                                 // End server
966
985
    break;
967
986
  case COM_BINLOG_DUMP:
968
987
    {
985
1004
      mysql_binlog_send(thd, thd->strdup(packet + 10), (my_off_t) pos, flags);
986
1005
      unregister_slave(thd,1,1);
987
1006
      /*  fake COM_QUIT -- if we get here, the thread needs to terminate */
988
 
      error = TRUE;
 
1007
      error = true;
989
1008
      break;
990
1009
    }
991
1010
  case COM_SHUTDOWN:
1006
1025
      my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
1007
1026
      break;
1008
1027
    }
 
1028
    DBUG_PRINT("quit",("Got shutdown command for level %u", level));
1009
1029
    general_log_print(thd, command, NullS);
1010
1030
    my_eof(thd);
1011
1031
    close_thread_tables(thd);                   // Free before kill
1012
1032
    kill_mysql();
1013
 
    error=TRUE;
 
1033
    error=true;
1014
1034
    break;
1015
1035
  }
1016
1036
  case COM_STATISTICS:
1101
1121
  }
1102
1122
 
1103
1123
  /* If commit fails, we should be able to reset the OK status. */
1104
 
  thd->main_da.can_overwrite_status= TRUE;
 
1124
  thd->main_da.can_overwrite_status= true;
1105
1125
  ha_autocommit_or_rollback(thd, thd->is_error());
1106
 
  thd->main_da.can_overwrite_status= FALSE;
 
1126
  thd->main_da.can_overwrite_status= false;
1107
1127
 
1108
1128
  thd->transaction.stmt.reset();
1109
1129
 
1138
1158
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1139
1159
  thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
1140
1160
  free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
1141
 
  return(error);
 
1161
  DBUG_RETURN(error);
1142
1162
}
1143
1163
 
1144
1164
 
1145
1165
void log_slow_statement(THD *thd)
1146
1166
{
 
1167
  DBUG_ENTER("log_slow_statement");
1147
1168
 
1148
1169
  /*
1149
1170
    The following should never be true with our current code base,
1151
1172
    statement in a trigger or stored function
1152
1173
  */
1153
1174
  if (unlikely(thd->in_sub_stmt))
1154
 
    return;                           // Don't set time for sub stmt
 
1175
    DBUG_VOID_RETURN;                           // Don't set time for sub stmt
1155
1176
 
1156
1177
  /*
1157
1178
    Do not log administrative statements unless the appropriate option is
1175
1196
      slow_log_print(thd, thd->query, thd->query_length, end_utime_of_query);
1176
1197
    }
1177
1198
  }
1178
 
  return;
 
1199
  DBUG_VOID_RETURN;
1179
1200
}
1180
1201
 
1181
1202
 
1209
1230
                         enum enum_schema_tables schema_table_idx)
1210
1231
{
1211
1232
  SELECT_LEX *schema_select_lex= NULL;
 
1233
  DBUG_ENTER("prepare_schema_table");
1212
1234
 
1213
1235
  switch (schema_table_idx) {
1214
1236
  case SCH_SCHEMATA:
1221
1243
      if (lex->select_lex.db == NULL &&
1222
1244
          lex->copy_db_to(&lex->select_lex.db, &dummy))
1223
1245
      {
1224
 
        return(1);
 
1246
        DBUG_RETURN(1);
1225
1247
      }
1226
1248
      schema_select_lex= new SELECT_LEX();
1227
1249
      db.str= schema_select_lex->db= lex->select_lex.db;
1231
1253
      if (check_db_name(&db))
1232
1254
      {
1233
1255
        my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
1234
 
        return(1);
 
1256
        DBUG_RETURN(1);
1235
1257
      }
1236
1258
      break;
1237
1259
    }
1245
1267
    schema_select_lex->parent_lex= lex;
1246
1268
    schema_select_lex->init_query();
1247
1269
    if (!schema_select_lex->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1248
 
      return(1);
 
1270
      DBUG_RETURN(1);
1249
1271
    lex->query_tables_last= query_tables_last;
1250
1272
    break;
1251
1273
  }
1265
1287
  assert(select_lex);
1266
1288
  if (make_schema_select(thd, select_lex, schema_table_idx))
1267
1289
  {
1268
 
    return(1);
 
1290
    DBUG_RETURN(1);
1269
1291
  }
1270
1292
  TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
1271
1293
  assert(table_list);
1272
1294
  table_list->schema_select_lex= schema_select_lex;
1273
1295
  table_list->schema_table_reformed= 1;
1274
 
  return(0);
 
1296
  DBUG_RETURN(0);
1275
1297
}
1276
1298
 
1277
1299
 
1284
1306
  - query_length
1285
1307
 
1286
1308
  @retval
1287
 
    FALSE ok
 
1309
    false ok
1288
1310
  @retval
1289
 
    TRUE  error;  In this case thd->fatal_error is set
 
1311
    true  error;  In this case thd->fatal_error is set
1290
1312
*/
1291
1313
 
1292
1314
bool alloc_query(THD *thd, const char *packet, uint packet_length)
1309
1331
  if (!(thd->query= (char*) thd->memdup_w_gap((uchar*) (packet),
1310
1332
                                              packet_length,
1311
1333
                                              thd->db_length+ 1)))
1312
 
    return TRUE;
 
1334
    return true;
1313
1335
  thd->query[packet_length]=0;
1314
1336
  thd->query_length= packet_length;
1315
1337
 
1317
1339
  thd->packet.shrink(thd->variables.net_buffer_length);
1318
1340
  thd->convert_buffer.shrink(thd->variables.net_buffer_length);
1319
1341
 
1320
 
  return FALSE;
 
1342
  return false;
1321
1343
}
1322
1344
 
1323
1345
static void reset_one_shot_variables(THD *thd) 
1363
1385
    - SUSPEND and FOR MIGRATE are not supported yet. TODO
1364
1386
 
1365
1387
  @retval
1366
 
    FALSE       OK
 
1388
    false       OK
1367
1389
  @retval
1368
 
    TRUE        Error
 
1390
    true        Error
1369
1391
*/
1370
1392
 
1371
1393
int
1372
1394
mysql_execute_command(THD *thd)
1373
1395
{
1374
 
  int res= FALSE;
1375
 
  bool need_start_waiting= FALSE; // have protection against global read lock
 
1396
  int res= false;
 
1397
  bool need_start_waiting= false; // have protection against global read lock
1376
1398
  int  up_result= 0;
1377
1399
  LEX  *lex= thd->lex;
1378
1400
  /* first SELECT_LEX (have special meaning for many of non-SELECTcommands) */
1384
1406
  /* most outer SELECT_LEX_UNIT of query */
1385
1407
  SELECT_LEX_UNIT *unit= &lex->unit;
1386
1408
  /* Saved variable value */
 
1409
  DBUG_ENTER("mysql_execute_command");
1387
1410
 
1388
1411
  /*
1389
1412
    In many cases first table of main SELECT_LEX have special meaning =>
1458
1481
        */
1459
1482
        reset_one_shot_variables(thd);
1460
1483
      }
1461
 
      return(0);
 
1484
      DBUG_RETURN(0);
1462
1485
    }
1463
1486
  }
1464
1487
  else
1470
1493
    if (deny_updates_if_read_only_option(thd, all_tables))
1471
1494
    {
1472
1495
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1473
 
      return(-1);
 
1496
      DBUG_RETURN(-1);
1474
1497
    }
1475
1498
  } /* endif unlikely slave */
1476
1499
  status_var_increment(thd->status_var.com_stat[lex->sql_command]);
1477
1500
 
1478
 
  DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table == FALSE);
 
1501
  DBUG_ASSERT(thd->transaction.stmt.modified_non_trans_table == false);
1479
1502
  
1480
1503
  switch (lex->sql_command) {
1481
1504
  case SQLCOM_SHOW_STATUS:
1574
1597
    res= mysql_assign_to_keycache(thd, first_table, &lex->ident);
1575
1598
    break;
1576
1599
  }
1577
 
  case SQLCOM_PRELOAD_KEYS:
1578
 
  {
1579
 
    DBUG_ASSERT(first_table == all_tables && first_table != 0);
1580
 
    res = mysql_preload_keys(thd, first_table);
1581
 
    break;
1582
 
  }
1583
1600
  case SQLCOM_CHANGE_MASTER:
1584
1601
  {
1585
1602
    pthread_mutex_lock(&LOCK_active_mi);
1721
1738
      if (!(create_info.options & HA_LEX_CREATE_TMP_TABLE))
1722
1739
      {
1723
1740
        lex->link_first_table_back(create_table, link_to_local);
1724
 
        create_table->create= TRUE;
 
1741
        create_table->create= true;
1725
1742
      }
1726
1743
 
1727
1744
      if (!(res= open_and_lock_tables(thd, lex->query_tables)))
1987
2004
      /*
1988
2005
        Presumably, REPAIR and binlog writing doesn't require synchronization
1989
2006
      */
1990
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
2007
      write_bin_log(thd, true, thd->query, thd->query_length);
1991
2008
    }
1992
2009
    select_lex->table_list.first= (uchar*) first_table;
1993
2010
    lex->query_tables=all_tables;
2013
2030
      /*
2014
2031
        Presumably, ANALYZE and binlog writing doesn't require synchronization
2015
2032
      */
2016
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
2033
      write_bin_log(thd, true, thd->query, thd->query_length);
2017
2034
    }
2018
2035
    select_lex->table_list.first= (uchar*) first_table;
2019
2036
    lex->query_tables=all_tables;
2033
2050
      /*
2034
2051
        Presumably, OPTIMIZE and binlog writing doesn't require synchronization
2035
2052
      */
2036
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
2053
      write_bin_log(thd, true, thd->query, thd->query_length);
2037
2054
    }
2038
2055
    select_lex->table_list.first= (uchar*) first_table;
2039
2056
    lex->query_tables=all_tables;
2131
2148
      */
2132
2149
 
2133
2150
      Incident incident= INCIDENT_NONE;
 
2151
      DBUG_PRINT("debug", ("Just before generate_incident()"));
2134
2152
      DBUG_EXECUTE_IF("incident_database_resync_on_replace",
2135
2153
                      incident= INCIDENT_LOST_EVENTS;);
2136
2154
      if (incident)
2139
2157
        mysql_bin_log.write(&ev);
2140
2158
        mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
2141
2159
      }
 
2160
      DBUG_PRINT("debug", ("Just after generate_incident()"));
2142
2161
    }
2143
2162
#endif
2144
2163
  case SQLCOM_INSERT:
2260
2279
    res = mysql_delete(thd, all_tables, select_lex->where,
2261
2280
                       &select_lex->order_list,
2262
2281
                       unit->select_limit_cnt, select_lex->options,
2263
 
                       FALSE);
 
2282
                       false);
2264
2283
    break;
2265
2284
  }
2266
2285
  case SQLCOM_DELETE_MULTI:
2280
2299
    if ((res= multi_delete_precheck(thd, all_tables)))
2281
2300
      break;
2282
2301
 
2283
 
    /* condition will be TRUE on SP re-excuting */
 
2302
    /* condition will be true on SP re-excuting */
2284
2303
    if (select_lex->item_list.elements != 0)
2285
2304
      select_lex->item_list.empty();
2286
2305
    if (add_item_to_list(thd, new Item_null()))
2313
2332
      delete del_result;
2314
2333
    }
2315
2334
    else
2316
 
      res= TRUE;                                // Error
 
2335
      res= true;                                // Error
2317
2336
    break;
2318
2337
  }
2319
2338
  case SQLCOM_DROP_TABLE:
2357
2376
  {
2358
2377
    LEX_STRING db_str= { (char *) select_lex->db, strlen(select_lex->db) };
2359
2378
 
2360
 
    if (!mysql_change_db(thd, &db_str, FALSE))
 
2379
    if (!mysql_change_db(thd, &db_str, false))
2361
2380
      my_ok(thd);
2362
2381
 
2363
2382
    break;
2443
2462
      - only transactional locks are requested (lex->lock_transactional) and
2444
2463
      - no non-transactional locks exist (!thd->locked_tables).
2445
2464
    */
 
2465
    DBUG_PRINT("lock_info", ("lex->lock_transactional: %d  "
 
2466
                             "thd->locked_tables: 0x%lx",
 
2467
                             lex->lock_transactional,
 
2468
                             (long) thd->locked_tables));
2446
2469
    if (lex->lock_transactional && !thd->locked_tables)
2447
2470
    {
2448
2471
      int rc;
2484
2507
    {
2485
2508
      thd->locked_tables=thd->lock;
2486
2509
      thd->lock=0;
2487
 
      (void) set_handler_table_locks(thd, all_tables, FALSE);
 
2510
      (void) set_handler_table_locks(thd, all_tables, false);
 
2511
      DBUG_PRINT("lock_info", ("thd->locked_tables: 0x%lx",
 
2512
                               (long) thd->locked_tables));
2488
2513
      my_ok(thd);
2489
2514
    }
2490
2515
    else
2682
2707
      */
2683
2708
      if (!lex->no_write_to_binlog && write_to_binlog)
2684
2709
      {
2685
 
        write_bin_log(thd, FALSE, thd->query, thd->query_length);
 
2710
        write_bin_log(thd, false, thd->query, thd->query_length);
2686
2711
      }
2687
2712
      my_ok(thd);
2688
2713
    } 
2748
2773
    if (sv)
2749
2774
    {
2750
2775
      if (ha_release_savepoint(thd, sv))
2751
 
        res= TRUE; // cannot happen
 
2776
        res= true; // cannot happen
2752
2777
      else
2753
2778
        my_ok(thd);
2754
2779
      thd->transaction.savepoints=sv->prev;
2770
2795
    if (sv)
2771
2796
    {
2772
2797
      if (ha_rollback_to_savepoint(thd, sv))
2773
 
        res= TRUE; // cannot happen
 
2798
        res= true; // cannot happen
2774
2799
      else
2775
2800
      {
2776
2801
        if (((thd->options & OPTION_KEEP_LOG) || 
2822
2847
        be free'd when transaction ends anyway
2823
2848
      */
2824
2849
      if (ha_savepoint(thd, newsv))
2825
 
        res= TRUE;
 
2850
        res= true;
2826
2851
      else
2827
2852
      {
2828
2853
        newsv->prev=thd->transaction.savepoints;
2868
2893
  goto finish;
2869
2894
 
2870
2895
error:
2871
 
  res= TRUE;
 
2896
  res= true;
2872
2897
 
2873
2898
finish:
2874
2899
  if (need_start_waiting)
2879
2904
    */
2880
2905
    start_waiting_global_read_lock(thd);
2881
2906
  }
2882
 
  return(res || thd->is_error());
 
2907
  DBUG_RETURN(res || thd->is_error());
2883
2908
}
2884
2909
 
2885
2910
 
3024
3049
 
3025
3050
void mysql_reset_thd_for_next_command(THD *thd)
3026
3051
{
 
3052
  DBUG_ENTER("mysql_reset_thd_for_next_command");
3027
3053
  DBUG_ASSERT(! thd->in_sub_stmt);
3028
3054
  thd->free_list= 0;
3029
3055
  thd->select_number= 1;
3047
3073
  if (!(thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
3048
3074
  {
3049
3075
    thd->options&= ~OPTION_KEEP_LOG;
3050
 
    thd->transaction.all.modified_non_trans_table= FALSE;
 
3076
    thd->transaction.all.modified_non_trans_table= false;
3051
3077
  }
3052
3078
  DBUG_ASSERT(thd->security_ctx== &thd->main_security_ctx);
3053
 
  thd->thread_specific_used= FALSE;
 
3079
  thd->thread_specific_used= false;
3054
3080
 
3055
3081
  if (opt_bin_log)
3056
3082
  {
3069
3095
  */
3070
3096
  thd->reset_current_stmt_binlog_row_based();
3071
3097
 
3072
 
  return;
 
3098
  DBUG_VOID_RETURN;
3073
3099
}
3074
3100
 
3075
3101
 
3092
3118
{
3093
3119
  SELECT_LEX *select_lex;
3094
3120
  THD *thd= lex->thd;
 
3121
  DBUG_ENTER("mysql_new_select");
3095
3122
 
3096
3123
  if (!(select_lex= new (thd->mem_root) SELECT_LEX()))
3097
 
    return(1);
 
3124
    DBUG_RETURN(1);
3098
3125
  select_lex->select_number= ++thd->select_number;
3099
3126
  select_lex->parent_lex= lex; /* Used in init_query. */
3100
3127
  select_lex->init_query();
3103
3130
  if (lex->nest_level > (int) MAX_SELECT_NESTING)
3104
3131
  {
3105
3132
    my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
3106
 
    return(1);
 
3133
    DBUG_RETURN(1);
3107
3134
  }
3108
3135
  select_lex->nest_level= lex->nest_level;
3109
3136
  if (move_down)
3110
3137
  {
3111
3138
    SELECT_LEX_UNIT *unit;
3112
 
    lex->subqueries= TRUE;
 
3139
    lex->subqueries= true;
3113
3140
    /* first select_lex of subselect or derived table */
3114
3141
    if (!(unit= new (thd->mem_root) SELECT_LEX_UNIT()))
3115
 
      return(1);
 
3142
      DBUG_RETURN(1);
3116
3143
 
3117
3144
    unit->init_query();
3118
3145
    unit->init_select();
3133
3160
    if (lex->current_select->order_list.first && !lex->current_select->braces)
3134
3161
    {
3135
3162
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
3136
 
      return(1);
 
3163
      DBUG_RETURN(1);
3137
3164
    }
3138
3165
    select_lex->include_neighbour(lex->current_select);
3139
3166
    SELECT_LEX_UNIT *unit= select_lex->master_unit();                              
3140
3167
    if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->thd))
3141
 
      return(1);
 
3168
      DBUG_RETURN(1);
3142
3169
    select_lex->context.outer_context= 
3143
3170
                unit->first_select()->context.outer_context;
3144
3171
  }
3150
3177
    in subquery is SELECT query and we allow resolution of names in SELECT
3151
3178
    list
3152
3179
  */
3153
 
  select_lex->context.resolve_in_select_list= TRUE;
3154
 
  return(0);
 
3180
  select_lex->context.resolve_in_select_list= true;
 
3181
  DBUG_RETURN(0);
3155
3182
}
3156
3183
 
3157
3184
/**
3171
3198
  LEX_STRING tmp, null_lex_string;
3172
3199
  Item *var;
3173
3200
  char buff[MAX_SYS_VAR_LENGTH*2+4+8], *end;
 
3201
  DBUG_ENTER("create_select_for_variable");
3174
3202
 
3175
3203
  thd= current_thd;
3176
3204
  lex= thd->lex;
3189
3217
    var->set_name(buff, end-buff, system_charset_info);
3190
3218
    add_item_to_list(thd, var);
3191
3219
  }
3192
 
  return;
 
3220
  DBUG_VOID_RETURN;
3193
3221
}
3194
3222
 
3195
3223
 
3224
3252
void mysql_parse(THD *thd, const char *inBuf, uint length,
3225
3253
                 const char ** found_semicolon)
3226
3254
{
 
3255
  DBUG_ENTER("mysql_parse");
3227
3256
 
3228
3257
  DBUG_EXECUTE_IF("parser_debug", turn_parser_debug_on(););
3229
3258
 
3278
3307
      }
3279
3308
    }
3280
3309
    else
 
3310
    {
3281
3311
      DBUG_ASSERT(thd->is_error());
3282
 
 
 
3312
      DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
 
3313
                         thd->is_fatal_error));
 
3314
    }
3283
3315
    lex->unit.cleanup();
3284
3316
    thd_proc_info(thd, "freeing items");
3285
3317
    thd->end_statement();
3287
3319
    DBUG_ASSERT(thd->change_list.is_empty());
3288
3320
  }
3289
3321
 
3290
 
  return;
 
3322
  DBUG_VOID_RETURN;
3291
3323
}
3292
3324
 
3293
3325
 
3306
3338
{
3307
3339
  LEX *lex= thd->lex;
3308
3340
  bool error= 0;
 
3341
  DBUG_ENTER("mysql_test_parse_for_slave");
3309
3342
 
3310
3343
  Lex_input_stream lip(thd, inBuf, length);
3311
3344
  lex_start(thd);
3316
3349
    error= 1;                  /* Ignore question */
3317
3350
  thd->end_statement();
3318
3351
  thd->cleanup_after_query();
3319
 
  return(error);
 
3352
  DBUG_RETURN(error);
3320
3353
}
3321
3354
#endif
3322
3355
 
3341
3374
{
3342
3375
  register Create_field *new_field;
3343
3376
  LEX  *lex= thd->lex;
 
3377
  DBUG_ENTER("add_field_to_list");
3344
3378
 
3345
3379
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
3346
 
    return(1);                          /* purecov: inspected */
 
3380
    DBUG_RETURN(1);                             /* purecov: inspected */
3347
3381
 
3348
3382
  if (type_modifier & PRI_KEY_FLAG)
3349
3383
  {
3380
3414
         type == MYSQL_TYPE_TIMESTAMP))
3381
3415
    {
3382
3416
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3383
 
      return(1);
 
3417
      DBUG_RETURN(1);
3384
3418
    }
3385
3419
    else if (default_value->type() == Item::NULL_ITEM)
3386
3420
    {
3389
3423
          NOT_NULL_FLAG)
3390
3424
      {
3391
3425
        my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3392
 
        return(1);
 
3426
        DBUG_RETURN(1);
3393
3427
      }
3394
3428
    }
3395
3429
    else if (type_modifier & AUTO_INCREMENT_FLAG)
3396
3430
    {
3397
3431
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3398
 
      return(1);
 
3432
      DBUG_RETURN(1);
3399
3433
    }
3400
3434
  }
3401
3435
 
3402
3436
  if (on_update_value && type != MYSQL_TYPE_TIMESTAMP)
3403
3437
  {
3404
3438
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
3405
 
    return(1);
 
3439
    DBUG_RETURN(1);
3406
3440
  }
3407
3441
 
3408
3442
  if (!(new_field= new Create_field()) ||
3410
3444
                      default_value, on_update_value, comment, change,
3411
3445
                      interval_list, cs, 0,
3412
3446
                      storage_type, column_format))
3413
 
    return(1);
 
3447
    DBUG_RETURN(1);
3414
3448
 
3415
3449
  lex->alter_info.create_list.push_back(new_field);
3416
3450
  lex->last_field=new_field;
3417
 
  return(0);
 
3451
  DBUG_RETURN(0);
3418
3452
}
3419
3453
 
3420
3454
 
3449
3483
bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
3450
3484
{
3451
3485
  ORDER *order;
 
3486
  DBUG_ENTER("add_to_list");
3452
3487
  if (!(order = (ORDER *) thd->alloc(sizeof(ORDER))))
3453
 
    return(1);
 
3488
    DBUG_RETURN(1);
3454
3489
  order->item_ptr= item;
3455
3490
  order->item= &order->item_ptr;
3456
3491
  order->asc = asc;
3458
3493
  order->used=0;
3459
3494
  order->counter_used= 0;
3460
3495
  list.link_in_list((uchar*) order,(uchar**) &order->next);
3461
 
  return(0);
 
3496
  DBUG_RETURN(0);
3462
3497
}
3463
3498
 
3464
3499
 
3493
3528
  TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
3494
3529
  char *alias_str;
3495
3530
  LEX *lex= thd->lex;
 
3531
  DBUG_ENTER("add_table_to_list");
3496
3532
 
3497
3533
  if (!table)
3498
 
    return(0);                          // End of memory
 
3534
    DBUG_RETURN(0);                             // End of memory
3499
3535
  alias_str= alias ? alias->str : table->table.str;
3500
3536
  if (!test(table_options & TL_OPTION_ALIAS) && 
3501
3537
      check_table_name(table->table.str, table->table.length))
3502
3538
  {
3503
3539
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
3504
 
    return(0);
 
3540
    DBUG_RETURN(0);
3505
3541
  }
3506
3542
 
3507
 
  if (table->is_derived_table() == FALSE && table->db.str &&
 
3543
  if (table->is_derived_table() == false && table->db.str &&
3508
3544
      check_db_name(&table->db))
3509
3545
  {
3510
3546
    my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
3511
 
    return(0);
 
3547
    DBUG_RETURN(0);
3512
3548
  }
3513
3549
 
3514
3550
  if (!alias)                                   /* Alias is case sensitive */
3517
3553
    {
3518
3554
      my_message(ER_DERIVED_MUST_HAVE_ALIAS,
3519
3555
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
3520
 
      return(0);
 
3556
      DBUG_RETURN(0);
3521
3557
    }
3522
3558
    if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1)))
3523
 
      return(0);
 
3559
      DBUG_RETURN(0);
3524
3560
  }
3525
3561
  if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
3526
 
    return(0);                          /* purecov: inspected */
 
3562
    DBUG_RETURN(0);                             /* purecov: inspected */
3527
3563
  if (table->db.str)
3528
3564
  {
3529
 
    ptr->is_fqtn= TRUE;
 
3565
    ptr->is_fqtn= true;
3530
3566
    ptr->db= table->db.str;
3531
3567
    ptr->db_length= table->db.length;
3532
3568
  }
3533
3569
  else if (lex->copy_db_to(&ptr->db, &ptr->db_length))
3534
 
    return(0);
 
3570
    DBUG_RETURN(0);
3535
3571
  else
3536
 
    ptr->is_fqtn= FALSE;
 
3572
    ptr->is_fqtn= false;
3537
3573
 
3538
3574
  ptr->alias= alias_str;
3539
 
  ptr->is_alias= alias ? TRUE : FALSE;
 
3575
  ptr->is_alias= alias ? true : false;
3540
3576
  if (lower_case_table_names && table->table.length)
3541
3577
    table->table.length= my_casedn_str(files_charset_info, table->table.str);
3542
3578
  ptr->table_name=table->table.str;
3563
3599
    {
3564
3600
      my_error(ER_UNKNOWN_TABLE, MYF(0),
3565
3601
               ptr->table_name, INFORMATION_SCHEMA_NAME.str);
3566
 
      return(0);
 
3602
      DBUG_RETURN(0);
3567
3603
    }
3568
3604
    ptr->schema_table_name= ptr->table_name;
3569
3605
    ptr->schema_table= schema_table;
3584
3620
          !strcmp(ptr->db, tables->db))
3585
3621
      {
3586
3622
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */
3587
 
        return(0);                              /* purecov: tested */
 
3623
        DBUG_RETURN(0);                         /* purecov: tested */
3588
3624
      }
3589
3625
    }
3590
3626
  }
3619
3655
  ptr->next_name_resolution_table= NULL;
3620
3656
  /* Link table in global list (all used tables) */
3621
3657
  lex->add_to_query_tables(ptr);
3622
 
  return(ptr);
 
3658
  DBUG_RETURN(ptr);
3623
3659
}
3624
3660
 
3625
3661
 
3646
3682
{
3647
3683
  TABLE_LIST *ptr;
3648
3684
  NESTED_JOIN *nested_join;
 
3685
  DBUG_ENTER("init_nested_join");
3649
3686
 
3650
3687
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3651
3688
                                       sizeof(NESTED_JOIN))))
3652
 
    return(1);
 
3689
    DBUG_RETURN(1);
3653
3690
  nested_join= ptr->nested_join=
3654
3691
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3655
3692
 
3660
3697
  embedding= ptr;
3661
3698
  join_list= &nested_join->join_list;
3662
3699
  join_list->empty();
3663
 
  return(0);
 
3700
  DBUG_RETURN(0);
3664
3701
}
3665
3702
 
3666
3703
 
3682
3719
{
3683
3720
  TABLE_LIST *ptr;
3684
3721
  NESTED_JOIN *nested_join;
 
3722
  DBUG_ENTER("end_nested_join");
3685
3723
 
3686
3724
  DBUG_ASSERT(embedding);
3687
3725
  ptr= embedding;
3702
3740
    join_list->pop();
3703
3741
    ptr= 0;                                     // return value
3704
3742
  }
3705
 
  return(ptr);
 
3743
  DBUG_RETURN(ptr);
3706
3744
}
3707
3745
 
3708
3746
 
3724
3762
  TABLE_LIST *ptr;
3725
3763
  NESTED_JOIN *nested_join;
3726
3764
  List<TABLE_LIST> *embedded_list;
 
3765
  DBUG_ENTER("nest_last_join");
3727
3766
 
3728
3767
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3729
3768
                                       sizeof(NESTED_JOIN))))
3730
 
    return(0);
 
3769
    DBUG_RETURN(0);
3731
3770
  nested_join= ptr->nested_join=
3732
3771
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3733
3772
 
3745
3784
    embedded_list->push_back(table);
3746
3785
    if (table->natural_join)
3747
3786
    {
3748
 
      ptr->is_natural_join= TRUE;
 
3787
      ptr->is_natural_join= true;
3749
3788
      /*
3750
3789
        If this is a JOIN ... USING, move the list of joined fields to the
3751
3790
        table reference that describes the join.
3756
3795
  }
3757
3796
  join_list->push_front(ptr);
3758
3797
  nested_join->used_tables= nested_join->not_null_tables= (table_map) 0;
3759
 
  return(ptr);
 
3798
  DBUG_RETURN(ptr);
3760
3799
}
3761
3800
 
3762
3801
 
3776
3815
 
3777
3816
void st_select_lex::add_joined_table(TABLE_LIST *table)
3778
3817
{
 
3818
  DBUG_ENTER("add_joined_table");
3779
3819
  join_list->push_front(table);
3780
3820
  table->join_list= join_list;
3781
3821
  table->embedding= embedding;
3782
 
  return;
 
3822
  DBUG_VOID_RETURN;
3783
3823
}
3784
3824
 
3785
3825
 
3818
3858
{
3819
3859
  TABLE_LIST *tab2= join_list->pop();
3820
3860
  TABLE_LIST *tab1= join_list->pop();
 
3861
  DBUG_ENTER("convert_right_join");
3821
3862
 
3822
3863
  join_list->push_front(tab2);
3823
3864
  join_list->push_front(tab1);
3824
3865
  tab1->outer_join|= JOIN_TYPE_RIGHT;
3825
3866
 
3826
 
  return(tab1);
 
3867
  DBUG_RETURN(tab1);
3827
3868
}
3828
3869
 
3829
3870
/**
3840
3881
void st_select_lex::set_lock_for_tables(thr_lock_type lock_type)
3841
3882
{
3842
3883
  bool for_update= lock_type >= TL_READ_NO_INSERT;
 
3884
  DBUG_ENTER("set_lock_for_tables");
 
3885
  DBUG_PRINT("enter", ("lock_type: %d  for_update: %d", lock_type,
 
3886
                       for_update));
3843
3887
 
3844
3888
  for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first;
3845
3889
       tables;
3848
3892
    tables->lock_type= lock_type;
3849
3893
    tables->updating=  for_update;
3850
3894
  }
3851
 
  return;
 
3895
  DBUG_VOID_RETURN;
3852
3896
}
3853
3897
 
3854
3898
 
3881
3925
bool st_select_lex_unit::add_fake_select_lex(THD *thd_arg)
3882
3926
{
3883
3927
  SELECT_LEX *first_sl= first_select();
 
3928
  DBUG_ENTER("add_fake_select_lex");
3884
3929
  DBUG_ASSERT(!fake_select_lex);
3885
3930
 
3886
3931
  if (!(fake_select_lex= new (thd_arg->mem_root) SELECT_LEX()))
3887
 
      return(1);
 
3932
      DBUG_RETURN(1);
3888
3933
  fake_select_lex->include_standalone(this, 
3889
3934
                                      (SELECT_LEX_NODE**)&fake_select_lex);
3890
3935
  fake_select_lex->select_number= INT_MAX;
3895
3940
 
3896
3941
  fake_select_lex->context.outer_context=first_sl->context.outer_context;
3897
3942
  /* allow item list resolving in fake select for ORDER BY */
3898
 
  fake_select_lex->context.resolve_in_select_list= TRUE;
 
3943
  fake_select_lex->context.resolve_in_select_list= true;
3899
3944
  fake_select_lex->context.select_lex= fake_select_lex;
3900
3945
 
3901
3946
  if (!is_union())
3911
3956
    thd_arg->lex->current_select= fake_select_lex;
3912
3957
  }
3913
3958
  thd_arg->lex->pop_context();
3914
 
  return(0);
 
3959
  DBUG_RETURN(0);
3915
3960
}
3916
3961
 
3917
3962
 
3929
3974
  @param right_op  rigth operand of the JOIN
3930
3975
 
3931
3976
  @retval
3932
 
    FALSE  if all is OK
 
3977
    false  if all is OK
3933
3978
  @retval
3934
 
    TRUE   if a memory allocation error occured
 
3979
    true   if a memory allocation error occured
3935
3980
*/
3936
3981
 
3937
3982
bool
3940
3985
{
3941
3986
  Name_resolution_context *on_context;
3942
3987
  if (!(on_context= new (thd->mem_root) Name_resolution_context))
3943
 
    return TRUE;
 
3988
    return true;
3944
3989
  on_context->init();
3945
3990
  on_context->first_name_resolution_table=
3946
3991
    left_op->first_leaf_for_name_resolution();
3959
4004
  @param expr  the condition to be added to the ON clause
3960
4005
 
3961
4006
  @retval
3962
 
    FALSE  if there was some error
 
4007
    false  if there was some error
3963
4008
  @retval
3964
 
    TRUE   if all is OK
 
4009
    true   if all is OK
3965
4010
*/
3966
4011
 
3967
4012
void add_join_on(TABLE_LIST *b, Item *expr)
4118
4163
      tmp_write_to_binlog= 0;
4119
4164
      if (lock_global_read_lock(thd))
4120
4165
        return 1;                               // Killed
4121
 
      result= close_cached_tables(thd, tables, FALSE, (options & REFRESH_FAST) ?
4122
 
                                  FALSE : TRUE, TRUE);
 
4166
      result= close_cached_tables(thd, tables, false, (options & REFRESH_FAST) ?
 
4167
                                  false : true, true);
4123
4168
      if (make_global_read_lock_block_commit(thd)) // Killed
4124
4169
      {
4125
4170
        /* Don't leave things in a half-locked state */
4128
4173
      }
4129
4174
    }
4130
4175
    else
4131
 
      result= close_cached_tables(thd, tables, FALSE, (options & REFRESH_FAST) ?
4132
 
                                  FALSE : TRUE, FALSE);
 
4176
      result= close_cached_tables(thd, tables, false, (options & REFRESH_FAST) ?
 
4177
                                  false : true, false);
4133
4178
    my_dbopt_cleanup();
4134
4179
  }
4135
4180
  if (thd && (options & REFRESH_STATUS))
4173
4218
{
4174
4219
  THD *tmp;
4175
4220
  uint error=ER_NO_SUCH_THREAD;
 
4221
  DBUG_ENTER("kill_one_thread");
 
4222
  DBUG_PRINT("enter", ("id=%lu only_kill=%d", id, only_kill_query));
4176
4223
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
4177
4224
  I_List_iterator<THD> it(threads);
4178
4225
  while ((tmp=it++))
4192
4239
    error=0;
4193
4240
    pthread_mutex_unlock(&tmp->LOCK_delete);
4194
4241
  }
4195
 
  return(error);
 
4242
  DBUG_PRINT("exit", ("%d", error));
 
4243
  DBUG_RETURN(error);
4196
4244
}
4197
4245
 
4198
4246
 
4343
4391
  @param tables Global/local table list (have to be the same)
4344
4392
 
4345
4393
  @retval
4346
 
    FALSE OK
 
4394
    false OK
4347
4395
  @retval
4348
 
    TRUE  Error
 
4396
    true  Error
4349
4397
*/
4350
4398
 
4351
4399
bool multi_update_precheck(THD *thd, TABLE_LIST *tables)
4353
4401
  const char *msg= 0;
4354
4402
  LEX *lex= thd->lex;
4355
4403
  SELECT_LEX *select_lex= &lex->select_lex;
 
4404
  DBUG_ENTER("multi_update_precheck");
4356
4405
 
4357
4406
  if (select_lex->item_list.elements != lex->value_list.elements)
4358
4407
  {
4359
4408
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4360
 
    return(TRUE);
 
4409
    DBUG_RETURN(true);
4361
4410
  }
4362
4411
 
4363
4412
  if (select_lex->order_list.elements)
4367
4416
  if (msg)
4368
4417
  {
4369
4418
    my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg);
4370
 
    return(TRUE);
 
4419
    DBUG_RETURN(true);
4371
4420
  }
4372
 
  return(FALSE);
 
4421
  DBUG_RETURN(false);
4373
4422
}
4374
4423
 
4375
4424
/**
4379
4428
  @param tables         Global/local table list
4380
4429
 
4381
4430
  @retval
4382
 
    FALSE OK
 
4431
    false OK
4383
4432
  @retval
4384
 
    TRUE  error
 
4433
    true  error
4385
4434
*/
4386
4435
 
4387
4436
bool multi_delete_precheck(THD *thd, TABLE_LIST *tables)
4388
4437
{
4389
4438
  SELECT_LEX *select_lex= &thd->lex->select_lex;
4390
4439
  TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
 
4440
  DBUG_ENTER("multi_delete_precheck");
4391
4441
 
4392
4442
  thd->lex->query_tables_own_last= 0;
4393
4443
  thd->lex->query_tables_own_last= save_query_tables_own_last;
4396
4446
  {
4397
4447
    my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
4398
4448
               ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
4399
 
    return(TRUE);
 
4449
    DBUG_RETURN(true);
4400
4450
  }
4401
 
  return(FALSE);
 
4451
  DBUG_RETURN(false);
4402
4452
}
4403
4453
 
4404
4454
 
4423
4473
                                            TABLE_LIST *tables)
4424
4474
{
4425
4475
  TABLE_LIST *match= NULL;
 
4476
  DBUG_ENTER("multi_delete_table_match");
4426
4477
 
4427
4478
  for (TABLE_LIST *elem= tables; elem; elem= elem->next_local)
4428
4479
  {
4445
4496
    if (match)
4446
4497
    {
4447
4498
      my_error(ER_NONUNIQ_TABLE, MYF(0), elem->alias);
4448
 
      return(NULL);
 
4499
      DBUG_RETURN(NULL);
4449
4500
    }
4450
4501
 
4451
4502
    match= elem;
4454
4505
  if (!match)
4455
4506
    my_error(ER_UNKNOWN_TABLE, MYF(0), tbl->table_name, "MULTI DELETE");
4456
4507
 
4457
 
  return(match);
 
4508
  DBUG_RETURN(match);
4458
4509
}
4459
4510
 
4460
4511
 
4465
4516
  @param lex   pointer to LEX representing multi-delete
4466
4517
 
4467
4518
  @retval
4468
 
    FALSE   success
 
4519
    false   success
4469
4520
  @retval
4470
 
    TRUE    error
 
4521
    true    error
4471
4522
*/
4472
4523
 
4473
4524
bool multi_delete_set_locks_and_link_aux_tables(LEX *lex)
4474
4525
{
4475
4526
  TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
4476
4527
  TABLE_LIST *target_tbl;
 
4528
  DBUG_ENTER("multi_delete_set_locks_and_link_aux_tables");
4477
4529
 
4478
4530
  lex->table_count= 0;
4479
4531
 
4484
4536
    /* All tables in aux_tables must be found in FROM PART */
4485
4537
    TABLE_LIST *walk= multi_delete_table_match(lex, target_tbl, tables);
4486
4538
    if (!walk)
4487
 
      return(TRUE);
 
4539
      DBUG_RETURN(true);
4488
4540
    if (!walk->derived)
4489
4541
    {
4490
4542
      target_tbl->table_name= walk->table_name;
4494
4546
    walk->lock_type= target_tbl->lock_type;
4495
4547
    target_tbl->correspondent_table= walk;      // Remember corresponding table
4496
4548
  }
4497
 
  return(FALSE);
 
4549
  DBUG_RETURN(false);
4498
4550
}
4499
4551
 
4500
4552
 
4505
4557
  @param tables Global table list
4506
4558
 
4507
4559
  @retval
4508
 
    FALSE OK
 
4560
    false OK
4509
4561
  @retval
4510
 
    TRUE  Error
 
4562
    true  Error
4511
4563
*/
4512
4564
 
4513
4565
bool update_precheck(THD *thd, TABLE_LIST *tables)
4514
4566
{
 
4567
  DBUG_ENTER("update_precheck");
4515
4568
  if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
4516
4569
  {
4517
4570
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4518
 
    return(TRUE);
 
4571
    DBUG_RETURN(true);
4519
4572
  }
4520
 
  return(FALSE);
 
4573
  DBUG_RETURN(false);
4521
4574
}
4522
4575
 
4523
4576
 
4528
4581
  @param tables Global table list
4529
4582
 
4530
4583
  @retval
4531
 
    FALSE  OK
 
4584
    false  OK
4532
4585
  @retval
4533
 
    TRUE   error
 
4586
    true   error
4534
4587
*/
4535
4588
 
4536
4589
bool insert_precheck(THD *thd, TABLE_LIST *tables)
4537
4590
{
4538
4591
  LEX *lex= thd->lex;
 
4592
  DBUG_ENTER("insert_precheck");
4539
4593
 
4540
4594
  /*
4541
4595
    Check that we have modify privileges for the first table and
4544
4598
  if (lex->update_list.elements != lex->value_list.elements)
4545
4599
  {
4546
4600
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4547
 
    return(TRUE);
 
4601
    DBUG_RETURN(true);
4548
4602
  }
4549
 
  return(FALSE);
 
4603
  DBUG_RETURN(false);
4550
4604
}
4551
4605
 
4552
4606
 
4558
4612
  @param create_table           Table which will be created
4559
4613
 
4560
4614
  @retval
4561
 
    FALSE   OK
 
4615
    false   OK
4562
4616
  @retval
4563
 
    TRUE   Error
 
4617
    true   Error
4564
4618
*/
4565
4619
 
4566
4620
bool create_table_precheck(THD *thd, TABLE_LIST *tables,
4568
4622
{
4569
4623
  LEX *lex= thd->lex;
4570
4624
  SELECT_LEX *select_lex= &lex->select_lex;
4571
 
  bool error= TRUE;                                 // Error message is given
 
4625
  bool error= true;                                 // Error message is given
 
4626
  DBUG_ENTER("create_table_precheck");
4572
4627
 
4573
4628
  if (create_table && (strcmp(create_table->db, "information_schema") == 0))
4574
4629
  {
4575
4630
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
4576
 
    return(TRUE);
 
4631
    DBUG_RETURN(true);
4577
4632
  }
4578
4633
 
4579
4634
  if (select_lex->item_list.elements)
4596
4651
          find_table_in_global_list(tables, create_table->db,
4597
4652
                                    create_table->table_name))
4598
4653
      {
4599
 
        error= FALSE;
 
4654
        error= false;
4600
4655
        goto err;
4601
4656
      }
4602
4657
    }
4603
4658
#endif
4604
4659
  }
4605
 
  error= FALSE;
 
4660
  error= false;
4606
4661
 
4607
 
  return(error);
 
4662
  DBUG_RETURN(error);
4608
4663
}
4609
4664
 
4610
4665
 
4650
4705
  @param max_length  max length
4651
4706
 
4652
4707
  @retval
4653
 
    FALSE   the passed string is not longer than max_length
 
4708
    false   the passed string is not longer than max_length
4654
4709
  @retval
4655
 
    TRUE    the passed string is longer than max_length
 
4710
    true    the passed string is longer than max_length
4656
4711
 
4657
4712
  NOTE
4658
4713
    The function is not used in existing code but can be useful later?
4662
4717
                              uint max_byte_length)
4663
4718
{
4664
4719
  if (str->length <= max_byte_length)
4665
 
    return FALSE;
 
4720
    return false;
4666
4721
 
4667
4722
  my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_byte_length);
4668
4723
 
4669
 
  return TRUE;
 
4724
  return true;
4670
4725
}
4671
4726
 
4672
4727
 
4681
4736
      cs               string charset
4682
4737
 
4683
4738
  RETURN
4684
 
    FALSE   the passed string is not longer than max_char_length
4685
 
    TRUE    the passed string is longer than max_char_length
 
4739
    false   the passed string is not longer than max_char_length
 
4740
    true    the passed string is longer than max_char_length
4686
4741
*/
4687
4742
 
4688
4743
 
4695
4750
                                      max_char_length, &well_formed_error);
4696
4751
 
4697
4752
  if (!well_formed_error &&  str->length == res)
4698
 
    return FALSE;
 
4753
    return false;
4699
4754
 
4700
4755
  if (!no_error)
4701
4756
    my_error(ER_WRONG_STRING_LENGTH, MYF(0), str->str, err_msg, max_char_length);
4702
 
  return TRUE;
 
4757
  return true;
4703
4758
}
4704
4759
 
4705
4760
 
4723
4778
  if (well_formed_error)
4724
4779
  {
4725
4780
    my_error(ER_INVALID_CHARACTER_STRING, MYF(0), "identifier", str->str);
4726
 
    return TRUE;
 
4781
    return true;
4727
4782
  }
4728
4783
  
4729
4784
  if (str->length == res)
4730
 
    return FALSE;
 
4785
    return false;
4731
4786
 
4732
4787
  switch (err_code)
4733
4788
  {
4743
4798
    DBUG_ASSERT(0);
4744
4799
    break;
4745
4800
  }
4746
 
  return TRUE;
 
4801
  return true;
4747
4802
}
4748
4803
 
4749
4804
 
4764
4819
{
4765
4820
  char path[FN_REFLEN], conv_path[FN_REFLEN];
4766
4821
  uint dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
 
4822
  DBUG_ENTER("test_if_data_home_dir");
4767
4823
 
4768
4824
  if (!dir)
4769
 
    return(0);
 
4825
    DBUG_RETURN(0);
4770
4826
 
4771
4827
  (void) fn_format(path, dir, "", "",
4772
4828
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
4780
4836
                        (const uchar*) conv_path, home_dir_len,
4781
4837
                        (const uchar*) mysql_unpacked_real_data_home,
4782
4838
                        home_dir_len))
4783
 
        return(1);
 
4839
        DBUG_RETURN(1);
4784
4840
    }
4785
4841
    else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
4786
 
      return(1);
 
4842
      DBUG_RETURN(1);
4787
4843
  }
4788
 
  return(0);
 
4844
  DBUG_RETURN(0);
4789
4845
}
4790
4846
 
4791
4847
 
4801
4857
  @param creation_ctx Object creation context.
4802
4858
 
4803
4859
  @return Error status.
4804
 
    @retval FALSE on success.
4805
 
    @retval TRUE on parsing error.
 
4860
    @retval false on success.
 
4861
    @retval true on parsing error.
4806
4862
*/
4807
4863
 
4808
4864
bool parse_sql(THD *thd,