~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_parse.cc

Merged PatG's removal of various DBUG stuff with still keeping DBUG_ASSERT calls since they seem to be breaking test runs

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");
87
86
  if (unlikely(thd->in_sub_stmt))
88
87
  {
89
88
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
90
 
    DBUG_RETURN(1);
 
89
    return(1);
91
90
  }
92
91
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
93
92
  {
94
93
    my_error(ER_XAER_RMFAIL, MYF(0),
95
94
             xa_state_names[thd->transaction.xid_state.xa_state]);
96
 
    DBUG_RETURN(1);
 
95
    return(1);
97
96
  }
98
97
  if (thd->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN |
99
98
                      OPTION_TABLE_LOCK))
100
99
  {
101
 
    DBUG_PRINT("info",("options: 0x%llx", thd->options));
102
100
    /* Safety if one did "drop table" on locked tables */
103
101
    if (!thd->locked_tables)
104
102
      thd->options&= ~OPTION_TABLE_LOCK;
108
106
  }
109
107
  thd->options&= ~(OPTION_BEGIN | OPTION_KEEP_LOG);
110
108
  thd->transaction.all.modified_non_trans_table= FALSE;
111
 
  DBUG_RETURN(error);
 
109
  return(error);
112
110
}
113
111
 
114
112
 
292
290
    thd->fatal_error();
293
291
    goto end;
294
292
  }
295
 
  DBUG_ENTER("handle_bootstrap");
296
293
 
297
294
  pthread_detach_this_thread();
298
295
  thd->thread_stack= (char*) &thd;
352
349
    thd->query= (char*) thd->memdup_w_gap(buff, length+1, 
353
350
                                          thd->db_length+1);
354
351
    thd->query[length] = '\0';
355
 
    DBUG_PRINT("query",("%-.4096s",thd->query));
356
352
 
357
353
    /*
358
354
      We don't need to obtain LOCK_thread_count here because in bootstrap
384
380
  (void) pthread_cond_broadcast(&COND_thread_count);
385
381
  my_thread_end();
386
382
  pthread_exit(0);
387
 
  DBUG_RETURN(0);
 
383
  return(0);
388
384
}
389
385
 
390
386
/* This works because items are allocated with sql_alloc() */
392
388
void free_items(Item *item)
393
389
{
394
390
  Item *next;
395
 
  DBUG_ENTER("free_items");
396
391
  for (; item ; item=next)
397
392
  {
398
393
    next=item->next;
399
394
    item->delete_self();
400
395
  }
401
 
  DBUG_VOID_RETURN;
 
396
  return;
402
397
}
403
398
 
404
399
/* This works because items are allocated with sql_alloc() */
405
400
 
406
401
void cleanup_items(Item *item)
407
402
{
408
 
  DBUG_ENTER("cleanup_items");
409
403
  for (; item ; item=item->next)
410
404
    item->cleanup();
411
 
  DBUG_VOID_RETURN;
 
405
  return;
412
406
}
413
407
 
414
408
/**
425
419
{
426
420
  bool do_release= 0;
427
421
  int res= 0;
428
 
  DBUG_ENTER("end_trans");
429
422
 
430
423
  if (unlikely(thd->in_sub_stmt))
431
424
  {
432
425
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
433
 
    DBUG_RETURN(1);
 
426
    return(1);
434
427
  }
435
428
  if (thd->transaction.xid_state.xa_state != XA_NOTR)
436
429
  {
437
430
    my_error(ER_XAER_RMFAIL, MYF(0),
438
431
             xa_state_names[thd->transaction.xid_state.xa_state]);
439
 
    DBUG_RETURN(1);
 
432
    return(1);
440
433
  }
441
434
  switch (completion) {
442
435
  case COMMIT:
474
467
  default:
475
468
    res= -1;
476
469
    my_error(ER_UNKNOWN_COM_ERROR, MYF(0));
477
 
    DBUG_RETURN(-1);
 
470
    return(-1);
478
471
  }
479
472
 
480
473
  if (res < 0)
482
475
  else if ((res == 0) && do_release)
483
476
    thd->killed= THD::KILL_CONNECTION;
484
477
 
485
 
  DBUG_RETURN(res);
 
478
  return(res);
486
479
}
487
480
 
488
481
 
505
498
  ulong packet_length;
506
499
  NET *net= &thd->net;
507
500
  enum enum_server_command command;
508
 
  DBUG_ENTER("do_command");
509
501
 
510
502
  /*
511
503
    indicator of uninitialized lex => normal flow of errors handling
533
525
  packet_length= my_net_read(net);
534
526
  if (packet_length == packet_error)
535
527
  {
536
 
    DBUG_PRINT("info",("Got error %d reading command from socket %s",
537
 
                       net->error,
538
 
                       vio_description(net->vio)));
539
528
 
540
529
    /* Check if we can continue without closing the connection */
541
530
 
577
566
  if (command >= COM_END)
578
567
    command= COM_END;                           // Wrong command
579
568
 
580
 
  DBUG_PRINT("info",("Command on %s = %d (%s)",
581
 
                     vio_description(net->vio), command,
582
 
                     command_name[command].str));
583
569
 
584
570
  /* Restore read timeout value */
585
571
  my_net_set_read_timeout(net, thd->variables.net_read_timeout);
588
574
  return_value= dispatch_command(command, thd, packet+1, (uint) (packet_length-1));
589
575
 
590
576
out:
591
 
  DBUG_RETURN(return_value);
 
577
  return(return_value);
592
578
}
593
579
 
594
580
/**
609
595
static my_bool deny_updates_if_read_only_option(THD *thd,
610
596
                                                TABLE_LIST *all_tables)
611
597
{
612
 
  DBUG_ENTER("deny_updates_if_read_only_option");
613
598
 
614
599
  if (!opt_readonly)
615
 
    DBUG_RETURN(FALSE);
 
600
    return(FALSE);
616
601
 
617
602
  LEX *lex= thd->lex;
618
603
 
619
604
  if (!(sql_command_flags[lex->sql_command] & CF_CHANGES_DATA))
620
 
    DBUG_RETURN(FALSE);
 
605
    return(FALSE);
621
606
 
622
607
  /* Multi update is an exception and is dealt with later. */
623
608
  if (lex->sql_command == SQLCOM_UPDATE_MULTI)
624
 
    DBUG_RETURN(FALSE);
 
609
    return(FALSE);
625
610
 
626
611
  const my_bool create_temp_tables= 
627
612
    (lex->sql_command == SQLCOM_CREATE_TABLE) &&
645
630
      /*
646
631
        An attempt was made to modify one or more non-temporary tables.
647
632
      */
648
 
      DBUG_RETURN(TRUE);
 
633
      return(TRUE);
649
634
  }
650
635
 
651
636
 
652
637
  /* Assuming that only temporary tables are modified. */
653
 
  DBUG_RETURN(FALSE);
 
638
  return(FALSE);
654
639
}
655
640
 
656
641
/**
679
664
{
680
665
  NET *net= &thd->net;
681
666
  bool error= 0;
682
 
  DBUG_ENTER("dispatch_command");
683
 
  DBUG_PRINT("info",("packet: '%*.s'; command: %d", packet_length, packet, command));
684
667
 
685
668
  thd->command=command;
686
669
  /*
861
844
    const char* end_of_stmt= NULL;
862
845
 
863
846
    general_log_write(thd, command, thd->query, thd->query_length);
864
 
    DBUG_PRINT("query",("%-.4096s",thd->query));
865
847
 
866
848
    if (!(specialflag & SPECIAL_NO_PRIOR))
867
849
    {
917
899
      tmp_sched_param.sched_priority= WAIT_PRIOR;
918
900
      (void)pthread_setschedparam(pthread_self(), SCHED_OTHER, &tmp_sched_param);
919
901
    }
920
 
    DBUG_PRINT("info",("query ready"));
921
902
    break;
922
903
  }
923
904
  case COM_FIELD_LIST:                          // This isn't actually needed
1025
1006
      my_error(ER_NOT_SUPPORTED_YET, MYF(0), "this shutdown level");
1026
1007
      break;
1027
1008
    }
1028
 
    DBUG_PRINT("quit",("Got shutdown command for level %u", level));
1029
1009
    general_log_print(thd, command, NullS);
1030
1010
    my_eof(thd);
1031
1011
    close_thread_tables(thd);                   // Free before kill
1158
1138
  VOID(pthread_mutex_unlock(&LOCK_thread_count));
1159
1139
  thd->packet.shrink(thd->variables.net_buffer_length); // Reclaim some memory
1160
1140
  free_root(thd->mem_root,MYF(MY_KEEP_PREALLOC));
1161
 
  DBUG_RETURN(error);
 
1141
  return(error);
1162
1142
}
1163
1143
 
1164
1144
 
1165
1145
void log_slow_statement(THD *thd)
1166
1146
{
1167
 
  DBUG_ENTER("log_slow_statement");
1168
1147
 
1169
1148
  /*
1170
1149
    The following should never be true with our current code base,
1172
1151
    statement in a trigger or stored function
1173
1152
  */
1174
1153
  if (unlikely(thd->in_sub_stmt))
1175
 
    DBUG_VOID_RETURN;                           // Don't set time for sub stmt
 
1154
    return;                           // Don't set time for sub stmt
1176
1155
 
1177
1156
  /*
1178
1157
    Do not log administrative statements unless the appropriate option is
1196
1175
      slow_log_print(thd, thd->query, thd->query_length, end_utime_of_query);
1197
1176
    }
1198
1177
  }
1199
 
  DBUG_VOID_RETURN;
 
1178
  return;
1200
1179
}
1201
1180
 
1202
1181
 
1230
1209
                         enum enum_schema_tables schema_table_idx)
1231
1210
{
1232
1211
  SELECT_LEX *schema_select_lex= NULL;
1233
 
  DBUG_ENTER("prepare_schema_table");
1234
1212
 
1235
1213
  switch (schema_table_idx) {
1236
1214
  case SCH_SCHEMATA:
1243
1221
      if (lex->select_lex.db == NULL &&
1244
1222
          lex->copy_db_to(&lex->select_lex.db, &dummy))
1245
1223
      {
1246
 
        DBUG_RETURN(1);
 
1224
        return(1);
1247
1225
      }
1248
1226
      schema_select_lex= new SELECT_LEX();
1249
1227
      db.str= schema_select_lex->db= lex->select_lex.db;
1253
1231
      if (check_db_name(&db))
1254
1232
      {
1255
1233
        my_error(ER_WRONG_DB_NAME, MYF(0), db.str);
1256
 
        DBUG_RETURN(1);
 
1234
        return(1);
1257
1235
      }
1258
1236
      break;
1259
1237
    }
1267
1245
    schema_select_lex->parent_lex= lex;
1268
1246
    schema_select_lex->init_query();
1269
1247
    if (!schema_select_lex->add_table_to_list(thd, table_ident, 0, 0, TL_READ))
1270
 
      DBUG_RETURN(1);
 
1248
      return(1);
1271
1249
    lex->query_tables_last= query_tables_last;
1272
1250
    break;
1273
1251
  }
1287
1265
  assert(select_lex);
1288
1266
  if (make_schema_select(thd, select_lex, schema_table_idx))
1289
1267
  {
1290
 
    DBUG_RETURN(1);
 
1268
    return(1);
1291
1269
  }
1292
1270
  TABLE_LIST *table_list= (TABLE_LIST*) select_lex->table_list.first;
1293
1271
  assert(table_list);
1294
1272
  table_list->schema_select_lex= schema_select_lex;
1295
1273
  table_list->schema_table_reformed= 1;
1296
 
  DBUG_RETURN(0);
 
1274
  return(0);
1297
1275
}
1298
1276
 
1299
1277
 
1406
1384
  /* most outer SELECT_LEX_UNIT of query */
1407
1385
  SELECT_LEX_UNIT *unit= &lex->unit;
1408
1386
  /* Saved variable value */
1409
 
  DBUG_ENTER("mysql_execute_command");
1410
1387
 
1411
1388
  /*
1412
1389
    In many cases first table of main SELECT_LEX have special meaning =>
1481
1458
        */
1482
1459
        reset_one_shot_variables(thd);
1483
1460
      }
1484
 
      DBUG_RETURN(0);
 
1461
      return(0);
1485
1462
    }
1486
1463
  }
1487
1464
  else
1493
1470
    if (deny_updates_if_read_only_option(thd, all_tables))
1494
1471
    {
1495
1472
      my_error(ER_OPTION_PREVENTS_STATEMENT, MYF(0), "--read-only");
1496
 
      DBUG_RETURN(-1);
 
1473
      return(-1);
1497
1474
    }
1498
1475
  } /* endif unlikely slave */
1499
1476
  status_var_increment(thd->status_var.com_stat[lex->sql_command]);
2154
2131
      */
2155
2132
 
2156
2133
      Incident incident= INCIDENT_NONE;
2157
 
      DBUG_PRINT("debug", ("Just before generate_incident()"));
2158
2134
      DBUG_EXECUTE_IF("incident_database_resync_on_replace",
2159
2135
                      incident= INCIDENT_LOST_EVENTS;);
2160
2136
      if (incident)
2163
2139
        mysql_bin_log.write(&ev);
2164
2140
        mysql_bin_log.rotate_and_purge(RP_FORCE_ROTATE);
2165
2141
      }
2166
 
      DBUG_PRINT("debug", ("Just after generate_incident()"));
2167
2142
    }
2168
2143
#endif
2169
2144
  case SQLCOM_INSERT:
2468
2443
      - only transactional locks are requested (lex->lock_transactional) and
2469
2444
      - no non-transactional locks exist (!thd->locked_tables).
2470
2445
    */
2471
 
    DBUG_PRINT("lock_info", ("lex->lock_transactional: %d  "
2472
 
                             "thd->locked_tables: 0x%lx",
2473
 
                             lex->lock_transactional,
2474
 
                             (long) thd->locked_tables));
2475
2446
    if (lex->lock_transactional && !thd->locked_tables)
2476
2447
    {
2477
2448
      int rc;
2514
2485
      thd->locked_tables=thd->lock;
2515
2486
      thd->lock=0;
2516
2487
      (void) set_handler_table_locks(thd, all_tables, FALSE);
2517
 
      DBUG_PRINT("lock_info", ("thd->locked_tables: 0x%lx",
2518
 
                               (long) thd->locked_tables));
2519
2488
      my_ok(thd);
2520
2489
    }
2521
2490
    else
2910
2879
    */
2911
2880
    start_waiting_global_read_lock(thd);
2912
2881
  }
2913
 
  DBUG_RETURN(res || thd->is_error());
 
2882
  return(res || thd->is_error());
2914
2883
}
2915
2884
 
2916
2885
 
3055
3024
 
3056
3025
void mysql_reset_thd_for_next_command(THD *thd)
3057
3026
{
3058
 
  DBUG_ENTER("mysql_reset_thd_for_next_command");
3059
3027
  DBUG_ASSERT(! thd->in_sub_stmt);
3060
3028
  thd->free_list= 0;
3061
3029
  thd->select_number= 1;
3101
3069
  */
3102
3070
  thd->reset_current_stmt_binlog_row_based();
3103
3071
 
3104
 
  DBUG_VOID_RETURN;
 
3072
  return;
3105
3073
}
3106
3074
 
3107
3075
 
3124
3092
{
3125
3093
  SELECT_LEX *select_lex;
3126
3094
  THD *thd= lex->thd;
3127
 
  DBUG_ENTER("mysql_new_select");
3128
3095
 
3129
3096
  if (!(select_lex= new (thd->mem_root) SELECT_LEX()))
3130
 
    DBUG_RETURN(1);
 
3097
    return(1);
3131
3098
  select_lex->select_number= ++thd->select_number;
3132
3099
  select_lex->parent_lex= lex; /* Used in init_query. */
3133
3100
  select_lex->init_query();
3136
3103
  if (lex->nest_level > (int) MAX_SELECT_NESTING)
3137
3104
  {
3138
3105
    my_error(ER_TOO_HIGH_LEVEL_OF_NESTING_FOR_SELECT,MYF(0),MAX_SELECT_NESTING);
3139
 
    DBUG_RETURN(1);
 
3106
    return(1);
3140
3107
  }
3141
3108
  select_lex->nest_level= lex->nest_level;
3142
3109
  if (move_down)
3145
3112
    lex->subqueries= TRUE;
3146
3113
    /* first select_lex of subselect or derived table */
3147
3114
    if (!(unit= new (thd->mem_root) SELECT_LEX_UNIT()))
3148
 
      DBUG_RETURN(1);
 
3115
      return(1);
3149
3116
 
3150
3117
    unit->init_query();
3151
3118
    unit->init_select();
3166
3133
    if (lex->current_select->order_list.first && !lex->current_select->braces)
3167
3134
    {
3168
3135
      my_error(ER_WRONG_USAGE, MYF(0), "UNION", "ORDER BY");
3169
 
      DBUG_RETURN(1);
 
3136
      return(1);
3170
3137
    }
3171
3138
    select_lex->include_neighbour(lex->current_select);
3172
3139
    SELECT_LEX_UNIT *unit= select_lex->master_unit();                              
3173
3140
    if (!unit->fake_select_lex && unit->add_fake_select_lex(lex->thd))
3174
 
      DBUG_RETURN(1);
 
3141
      return(1);
3175
3142
    select_lex->context.outer_context= 
3176
3143
                unit->first_select()->context.outer_context;
3177
3144
  }
3184
3151
    list
3185
3152
  */
3186
3153
  select_lex->context.resolve_in_select_list= TRUE;
3187
 
  DBUG_RETURN(0);
 
3154
  return(0);
3188
3155
}
3189
3156
 
3190
3157
/**
3204
3171
  LEX_STRING tmp, null_lex_string;
3205
3172
  Item *var;
3206
3173
  char buff[MAX_SYS_VAR_LENGTH*2+4+8], *end;
3207
 
  DBUG_ENTER("create_select_for_variable");
3208
3174
 
3209
3175
  thd= current_thd;
3210
3176
  lex= thd->lex;
3223
3189
    var->set_name(buff, end-buff, system_charset_info);
3224
3190
    add_item_to_list(thd, var);
3225
3191
  }
3226
 
  DBUG_VOID_RETURN;
 
3192
  return;
3227
3193
}
3228
3194
 
3229
3195
 
3258
3224
void mysql_parse(THD *thd, const char *inBuf, uint length,
3259
3225
                 const char ** found_semicolon)
3260
3226
{
3261
 
  DBUG_ENTER("mysql_parse");
3262
3227
 
3263
3228
  DBUG_EXECUTE_IF("parser_debug", turn_parser_debug_on(););
3264
3229
 
3313
3278
      }
3314
3279
    }
3315
3280
    else
3316
 
    {
3317
3281
      DBUG_ASSERT(thd->is_error());
3318
 
      DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
3319
 
                         thd->is_fatal_error));
3320
 
    }
 
3282
 
3321
3283
    lex->unit.cleanup();
3322
3284
    thd_proc_info(thd, "freeing items");
3323
3285
    thd->end_statement();
3325
3287
    DBUG_ASSERT(thd->change_list.is_empty());
3326
3288
  }
3327
3289
 
3328
 
  DBUG_VOID_RETURN;
 
3290
  return;
3329
3291
}
3330
3292
 
3331
3293
 
3344
3306
{
3345
3307
  LEX *lex= thd->lex;
3346
3308
  bool error= 0;
3347
 
  DBUG_ENTER("mysql_test_parse_for_slave");
3348
3309
 
3349
3310
  Lex_input_stream lip(thd, inBuf, length);
3350
3311
  lex_start(thd);
3355
3316
    error= 1;                  /* Ignore question */
3356
3317
  thd->end_statement();
3357
3318
  thd->cleanup_after_query();
3358
 
  DBUG_RETURN(error);
 
3319
  return(error);
3359
3320
}
3360
3321
#endif
3361
3322
 
3380
3341
{
3381
3342
  register Create_field *new_field;
3382
3343
  LEX  *lex= thd->lex;
3383
 
  DBUG_ENTER("add_field_to_list");
3384
3344
 
3385
3345
  if (check_identifier_name(field_name, ER_TOO_LONG_IDENT))
3386
 
    DBUG_RETURN(1);                             /* purecov: inspected */
 
3346
    return(1);                          /* purecov: inspected */
3387
3347
 
3388
3348
  if (type_modifier & PRI_KEY_FLAG)
3389
3349
  {
3420
3380
         type == MYSQL_TYPE_TIMESTAMP))
3421
3381
    {
3422
3382
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3423
 
      DBUG_RETURN(1);
 
3383
      return(1);
3424
3384
    }
3425
3385
    else if (default_value->type() == Item::NULL_ITEM)
3426
3386
    {
3429
3389
          NOT_NULL_FLAG)
3430
3390
      {
3431
3391
        my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3432
 
        DBUG_RETURN(1);
 
3392
        return(1);
3433
3393
      }
3434
3394
    }
3435
3395
    else if (type_modifier & AUTO_INCREMENT_FLAG)
3436
3396
    {
3437
3397
      my_error(ER_INVALID_DEFAULT, MYF(0), field_name->str);
3438
 
      DBUG_RETURN(1);
 
3398
      return(1);
3439
3399
    }
3440
3400
  }
3441
3401
 
3442
3402
  if (on_update_value && type != MYSQL_TYPE_TIMESTAMP)
3443
3403
  {
3444
3404
    my_error(ER_INVALID_ON_UPDATE, MYF(0), field_name->str);
3445
 
    DBUG_RETURN(1);
 
3405
    return(1);
3446
3406
  }
3447
3407
 
3448
3408
  if (!(new_field= new Create_field()) ||
3450
3410
                      default_value, on_update_value, comment, change,
3451
3411
                      interval_list, cs, 0,
3452
3412
                      storage_type, column_format))
3453
 
    DBUG_RETURN(1);
 
3413
    return(1);
3454
3414
 
3455
3415
  lex->alter_info.create_list.push_back(new_field);
3456
3416
  lex->last_field=new_field;
3457
 
  DBUG_RETURN(0);
 
3417
  return(0);
3458
3418
}
3459
3419
 
3460
3420
 
3489
3449
bool add_to_list(THD *thd, SQL_LIST &list,Item *item,bool asc)
3490
3450
{
3491
3451
  ORDER *order;
3492
 
  DBUG_ENTER("add_to_list");
3493
3452
  if (!(order = (ORDER *) thd->alloc(sizeof(ORDER))))
3494
 
    DBUG_RETURN(1);
 
3453
    return(1);
3495
3454
  order->item_ptr= item;
3496
3455
  order->item= &order->item_ptr;
3497
3456
  order->asc = asc;
3499
3458
  order->used=0;
3500
3459
  order->counter_used= 0;
3501
3460
  list.link_in_list((uchar*) order,(uchar**) &order->next);
3502
 
  DBUG_RETURN(0);
 
3461
  return(0);
3503
3462
}
3504
3463
 
3505
3464
 
3534
3493
  TABLE_LIST *previous_table_ref; /* The table preceding the current one. */
3535
3494
  char *alias_str;
3536
3495
  LEX *lex= thd->lex;
3537
 
  DBUG_ENTER("add_table_to_list");
3538
3496
 
3539
3497
  if (!table)
3540
 
    DBUG_RETURN(0);                             // End of memory
 
3498
    return(0);                          // End of memory
3541
3499
  alias_str= alias ? alias->str : table->table.str;
3542
3500
  if (!test(table_options & TL_OPTION_ALIAS) && 
3543
3501
      check_table_name(table->table.str, table->table.length))
3544
3502
  {
3545
3503
    my_error(ER_WRONG_TABLE_NAME, MYF(0), table->table.str);
3546
 
    DBUG_RETURN(0);
 
3504
    return(0);
3547
3505
  }
3548
3506
 
3549
3507
  if (table->is_derived_table() == FALSE && table->db.str &&
3550
3508
      check_db_name(&table->db))
3551
3509
  {
3552
3510
    my_error(ER_WRONG_DB_NAME, MYF(0), table->db.str);
3553
 
    DBUG_RETURN(0);
 
3511
    return(0);
3554
3512
  }
3555
3513
 
3556
3514
  if (!alias)                                   /* Alias is case sensitive */
3559
3517
    {
3560
3518
      my_message(ER_DERIVED_MUST_HAVE_ALIAS,
3561
3519
                 ER(ER_DERIVED_MUST_HAVE_ALIAS), MYF(0));
3562
 
      DBUG_RETURN(0);
 
3520
      return(0);
3563
3521
    }
3564
3522
    if (!(alias_str= (char*) thd->memdup(alias_str,table->table.length+1)))
3565
 
      DBUG_RETURN(0);
 
3523
      return(0);
3566
3524
  }
3567
3525
  if (!(ptr = (TABLE_LIST *) thd->calloc(sizeof(TABLE_LIST))))
3568
 
    DBUG_RETURN(0);                             /* purecov: inspected */
 
3526
    return(0);                          /* purecov: inspected */
3569
3527
  if (table->db.str)
3570
3528
  {
3571
3529
    ptr->is_fqtn= TRUE;
3573
3531
    ptr->db_length= table->db.length;
3574
3532
  }
3575
3533
  else if (lex->copy_db_to(&ptr->db, &ptr->db_length))
3576
 
    DBUG_RETURN(0);
 
3534
    return(0);
3577
3535
  else
3578
3536
    ptr->is_fqtn= FALSE;
3579
3537
 
3605
3563
    {
3606
3564
      my_error(ER_UNKNOWN_TABLE, MYF(0),
3607
3565
               ptr->table_name, INFORMATION_SCHEMA_NAME.str);
3608
 
      DBUG_RETURN(0);
 
3566
      return(0);
3609
3567
    }
3610
3568
    ptr->schema_table_name= ptr->table_name;
3611
3569
    ptr->schema_table= schema_table;
3626
3584
          !strcmp(ptr->db, tables->db))
3627
3585
      {
3628
3586
        my_error(ER_NONUNIQ_TABLE, MYF(0), alias_str); /* purecov: tested */
3629
 
        DBUG_RETURN(0);                         /* purecov: tested */
 
3587
        return(0);                              /* purecov: tested */
3630
3588
      }
3631
3589
    }
3632
3590
  }
3661
3619
  ptr->next_name_resolution_table= NULL;
3662
3620
  /* Link table in global list (all used tables) */
3663
3621
  lex->add_to_query_tables(ptr);
3664
 
  DBUG_RETURN(ptr);
 
3622
  return(ptr);
3665
3623
}
3666
3624
 
3667
3625
 
3688
3646
{
3689
3647
  TABLE_LIST *ptr;
3690
3648
  NESTED_JOIN *nested_join;
3691
 
  DBUG_ENTER("init_nested_join");
3692
3649
 
3693
3650
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3694
3651
                                       sizeof(NESTED_JOIN))))
3695
 
    DBUG_RETURN(1);
 
3652
    return(1);
3696
3653
  nested_join= ptr->nested_join=
3697
3654
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3698
3655
 
3703
3660
  embedding= ptr;
3704
3661
  join_list= &nested_join->join_list;
3705
3662
  join_list->empty();
3706
 
  DBUG_RETURN(0);
 
3663
  return(0);
3707
3664
}
3708
3665
 
3709
3666
 
3725
3682
{
3726
3683
  TABLE_LIST *ptr;
3727
3684
  NESTED_JOIN *nested_join;
3728
 
  DBUG_ENTER("end_nested_join");
3729
3685
 
3730
3686
  DBUG_ASSERT(embedding);
3731
3687
  ptr= embedding;
3746
3702
    join_list->pop();
3747
3703
    ptr= 0;                                     // return value
3748
3704
  }
3749
 
  DBUG_RETURN(ptr);
 
3705
  return(ptr);
3750
3706
}
3751
3707
 
3752
3708
 
3768
3724
  TABLE_LIST *ptr;
3769
3725
  NESTED_JOIN *nested_join;
3770
3726
  List<TABLE_LIST> *embedded_list;
3771
 
  DBUG_ENTER("nest_last_join");
3772
3727
 
3773
3728
  if (!(ptr= (TABLE_LIST*) thd->calloc(ALIGN_SIZE(sizeof(TABLE_LIST))+
3774
3729
                                       sizeof(NESTED_JOIN))))
3775
 
    DBUG_RETURN(0);
 
3730
    return(0);
3776
3731
  nested_join= ptr->nested_join=
3777
3732
    ((NESTED_JOIN*) ((uchar*) ptr + ALIGN_SIZE(sizeof(TABLE_LIST))));
3778
3733
 
3801
3756
  }
3802
3757
  join_list->push_front(ptr);
3803
3758
  nested_join->used_tables= nested_join->not_null_tables= (table_map) 0;
3804
 
  DBUG_RETURN(ptr);
 
3759
  return(ptr);
3805
3760
}
3806
3761
 
3807
3762
 
3821
3776
 
3822
3777
void st_select_lex::add_joined_table(TABLE_LIST *table)
3823
3778
{
3824
 
  DBUG_ENTER("add_joined_table");
3825
3779
  join_list->push_front(table);
3826
3780
  table->join_list= join_list;
3827
3781
  table->embedding= embedding;
3828
 
  DBUG_VOID_RETURN;
 
3782
  return;
3829
3783
}
3830
3784
 
3831
3785
 
3864
3818
{
3865
3819
  TABLE_LIST *tab2= join_list->pop();
3866
3820
  TABLE_LIST *tab1= join_list->pop();
3867
 
  DBUG_ENTER("convert_right_join");
3868
3821
 
3869
3822
  join_list->push_front(tab2);
3870
3823
  join_list->push_front(tab1);
3871
3824
  tab1->outer_join|= JOIN_TYPE_RIGHT;
3872
3825
 
3873
 
  DBUG_RETURN(tab1);
 
3826
  return(tab1);
3874
3827
}
3875
3828
 
3876
3829
/**
3887
3840
void st_select_lex::set_lock_for_tables(thr_lock_type lock_type)
3888
3841
{
3889
3842
  bool for_update= lock_type >= TL_READ_NO_INSERT;
3890
 
  DBUG_ENTER("set_lock_for_tables");
3891
 
  DBUG_PRINT("enter", ("lock_type: %d  for_update: %d", lock_type,
3892
 
                       for_update));
3893
3843
 
3894
3844
  for (TABLE_LIST *tables= (TABLE_LIST*) table_list.first;
3895
3845
       tables;
3898
3848
    tables->lock_type= lock_type;
3899
3849
    tables->updating=  for_update;
3900
3850
  }
3901
 
  DBUG_VOID_RETURN;
 
3851
  return;
3902
3852
}
3903
3853
 
3904
3854
 
3931
3881
bool st_select_lex_unit::add_fake_select_lex(THD *thd_arg)
3932
3882
{
3933
3883
  SELECT_LEX *first_sl= first_select();
3934
 
  DBUG_ENTER("add_fake_select_lex");
3935
3884
  DBUG_ASSERT(!fake_select_lex);
3936
3885
 
3937
3886
  if (!(fake_select_lex= new (thd_arg->mem_root) SELECT_LEX()))
3938
 
      DBUG_RETURN(1);
 
3887
      return(1);
3939
3888
  fake_select_lex->include_standalone(this, 
3940
3889
                                      (SELECT_LEX_NODE**)&fake_select_lex);
3941
3890
  fake_select_lex->select_number= INT_MAX;
3962
3911
    thd_arg->lex->current_select= fake_select_lex;
3963
3912
  }
3964
3913
  thd_arg->lex->pop_context();
3965
 
  DBUG_RETURN(0);
 
3914
  return(0);
3966
3915
}
3967
3916
 
3968
3917
 
4224
4173
{
4225
4174
  THD *tmp;
4226
4175
  uint error=ER_NO_SUCH_THREAD;
4227
 
  DBUG_ENTER("kill_one_thread");
4228
 
  DBUG_PRINT("enter", ("id=%lu only_kill=%d", id, only_kill_query));
4229
4176
  VOID(pthread_mutex_lock(&LOCK_thread_count)); // For unlink from list
4230
4177
  I_List_iterator<THD> it(threads);
4231
4178
  while ((tmp=it++))
4245
4192
    error=0;
4246
4193
    pthread_mutex_unlock(&tmp->LOCK_delete);
4247
4194
  }
4248
 
  DBUG_PRINT("exit", ("%d", error));
4249
 
  DBUG_RETURN(error);
 
4195
  return(error);
4250
4196
}
4251
4197
 
4252
4198
 
4407
4353
  const char *msg= 0;
4408
4354
  LEX *lex= thd->lex;
4409
4355
  SELECT_LEX *select_lex= &lex->select_lex;
4410
 
  DBUG_ENTER("multi_update_precheck");
4411
4356
 
4412
4357
  if (select_lex->item_list.elements != lex->value_list.elements)
4413
4358
  {
4414
4359
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4415
 
    DBUG_RETURN(TRUE);
 
4360
    return(TRUE);
4416
4361
  }
4417
4362
 
4418
4363
  if (select_lex->order_list.elements)
4422
4367
  if (msg)
4423
4368
  {
4424
4369
    my_error(ER_WRONG_USAGE, MYF(0), "UPDATE", msg);
4425
 
    DBUG_RETURN(TRUE);
 
4370
    return(TRUE);
4426
4371
  }
4427
 
  DBUG_RETURN(FALSE);
 
4372
  return(FALSE);
4428
4373
}
4429
4374
 
4430
4375
/**
4443
4388
{
4444
4389
  SELECT_LEX *select_lex= &thd->lex->select_lex;
4445
4390
  TABLE_LIST **save_query_tables_own_last= thd->lex->query_tables_own_last;
4446
 
  DBUG_ENTER("multi_delete_precheck");
4447
4391
 
4448
4392
  thd->lex->query_tables_own_last= 0;
4449
4393
  thd->lex->query_tables_own_last= save_query_tables_own_last;
4452
4396
  {
4453
4397
    my_message(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE,
4454
4398
               ER(ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODE), MYF(0));
4455
 
    DBUG_RETURN(TRUE);
 
4399
    return(TRUE);
4456
4400
  }
4457
 
  DBUG_RETURN(FALSE);
 
4401
  return(FALSE);
4458
4402
}
4459
4403
 
4460
4404
 
4479
4423
                                            TABLE_LIST *tables)
4480
4424
{
4481
4425
  TABLE_LIST *match= NULL;
4482
 
  DBUG_ENTER("multi_delete_table_match");
4483
4426
 
4484
4427
  for (TABLE_LIST *elem= tables; elem; elem= elem->next_local)
4485
4428
  {
4502
4445
    if (match)
4503
4446
    {
4504
4447
      my_error(ER_NONUNIQ_TABLE, MYF(0), elem->alias);
4505
 
      DBUG_RETURN(NULL);
 
4448
      return(NULL);
4506
4449
    }
4507
4450
 
4508
4451
    match= elem;
4511
4454
  if (!match)
4512
4455
    my_error(ER_UNKNOWN_TABLE, MYF(0), tbl->table_name, "MULTI DELETE");
4513
4456
 
4514
 
  DBUG_RETURN(match);
 
4457
  return(match);
4515
4458
}
4516
4459
 
4517
4460
 
4531
4474
{
4532
4475
  TABLE_LIST *tables= (TABLE_LIST*)lex->select_lex.table_list.first;
4533
4476
  TABLE_LIST *target_tbl;
4534
 
  DBUG_ENTER("multi_delete_set_locks_and_link_aux_tables");
4535
4477
 
4536
4478
  lex->table_count= 0;
4537
4479
 
4542
4484
    /* All tables in aux_tables must be found in FROM PART */
4543
4485
    TABLE_LIST *walk= multi_delete_table_match(lex, target_tbl, tables);
4544
4486
    if (!walk)
4545
 
      DBUG_RETURN(TRUE);
 
4487
      return(TRUE);
4546
4488
    if (!walk->derived)
4547
4489
    {
4548
4490
      target_tbl->table_name= walk->table_name;
4552
4494
    walk->lock_type= target_tbl->lock_type;
4553
4495
    target_tbl->correspondent_table= walk;      // Remember corresponding table
4554
4496
  }
4555
 
  DBUG_RETURN(FALSE);
 
4497
  return(FALSE);
4556
4498
}
4557
4499
 
4558
4500
 
4570
4512
 
4571
4513
bool update_precheck(THD *thd, TABLE_LIST *tables)
4572
4514
{
4573
 
  DBUG_ENTER("update_precheck");
4574
4515
  if (thd->lex->select_lex.item_list.elements != thd->lex->value_list.elements)
4575
4516
  {
4576
4517
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4577
 
    DBUG_RETURN(TRUE);
 
4518
    return(TRUE);
4578
4519
  }
4579
 
  DBUG_RETURN(FALSE);
 
4520
  return(FALSE);
4580
4521
}
4581
4522
 
4582
4523
 
4595
4536
bool insert_precheck(THD *thd, TABLE_LIST *tables)
4596
4537
{
4597
4538
  LEX *lex= thd->lex;
4598
 
  DBUG_ENTER("insert_precheck");
4599
4539
 
4600
4540
  /*
4601
4541
    Check that we have modify privileges for the first table and
4604
4544
  if (lex->update_list.elements != lex->value_list.elements)
4605
4545
  {
4606
4546
    my_message(ER_WRONG_VALUE_COUNT, ER(ER_WRONG_VALUE_COUNT), MYF(0));
4607
 
    DBUG_RETURN(TRUE);
 
4547
    return(TRUE);
4608
4548
  }
4609
 
  DBUG_RETURN(FALSE);
 
4549
  return(FALSE);
4610
4550
}
4611
4551
 
4612
4552
 
4629
4569
  LEX *lex= thd->lex;
4630
4570
  SELECT_LEX *select_lex= &lex->select_lex;
4631
4571
  bool error= TRUE;                                 // Error message is given
4632
 
  DBUG_ENTER("create_table_precheck");
4633
4572
 
4634
4573
  if (create_table && (strcmp(create_table->db, "information_schema") == 0))
4635
4574
  {
4636
4575
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
4637
 
    DBUG_RETURN(TRUE);
 
4576
    return(TRUE);
4638
4577
  }
4639
4578
 
4640
4579
  if (select_lex->item_list.elements)
4665
4604
  }
4666
4605
  error= FALSE;
4667
4606
 
4668
 
  DBUG_RETURN(error);
 
4607
  return(error);
4669
4608
}
4670
4609
 
4671
4610
 
4825
4764
{
4826
4765
  char path[FN_REFLEN], conv_path[FN_REFLEN];
4827
4766
  uint dir_len, home_dir_len= strlen(mysql_unpacked_real_data_home);
4828
 
  DBUG_ENTER("test_if_data_home_dir");
4829
4767
 
4830
4768
  if (!dir)
4831
 
    DBUG_RETURN(0);
 
4769
    return(0);
4832
4770
 
4833
4771
  (void) fn_format(path, dir, "", "",
4834
4772
                   (MY_RETURN_REAL_PATH|MY_RESOLVE_SYMLINKS));
4842
4780
                        (const uchar*) conv_path, home_dir_len,
4843
4781
                        (const uchar*) mysql_unpacked_real_data_home,
4844
4782
                        home_dir_len))
4845
 
        DBUG_RETURN(1);
 
4783
        return(1);
4846
4784
    }
4847
4785
    else if (!memcmp(conv_path, mysql_unpacked_real_data_home, home_dir_len))
4848
 
      DBUG_RETURN(1);
 
4786
      return(1);
4849
4787
  }
4850
 
  DBUG_RETURN(0);
 
4788
  return(0);
4851
4789
}
4852
4790
 
4853
4791