~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to sql/sql_table.cc

  • Committer: Monty Taylor
  • Date: 2008-07-09 16:42:25 UTC
  • mto: (77.6.1 glibclient-merge)
  • mto: This revision was merged to the branch mainline in revision 112.
  • Revision ID: monty@inaugust.com-20080709164225-2r6n4j98nhxh031l
Moved test to tests... 

Show diffs side-by-side

added added

removed removed

Lines of Context:
79
79
{
80
80
  uint errors;
81
81
  uint res;
82
 
  DBUG_ENTER("filename_to_tablename");
83
 
  DBUG_PRINT("enter", ("from '%s'", from));
84
82
 
85
83
  if (!memcmp(from, tmp_file_prefix, tmp_file_prefix_length))
86
84
  {
103
101
    }
104
102
  }
105
103
 
106
 
  DBUG_PRINT("exit", ("to '%s'", to));
107
 
  DBUG_RETURN(res);
 
104
  return(res);
108
105
}
109
106
 
110
107
 
124
121
uint tablename_to_filename(const char *from, char *to, uint to_length)
125
122
{
126
123
  uint errors, length;
127
 
  DBUG_ENTER("tablename_to_filename");
128
 
  DBUG_PRINT("enter", ("from '%s'", from));
129
124
 
130
125
  if (from[0] == '#' && !strncmp(from, MYSQL50_TABLE_NAME_PREFIX,
131
126
                                 MYSQL50_TABLE_NAME_PREFIX_LENGTH))
132
 
    DBUG_RETURN((uint) (strmake(to, from+MYSQL50_TABLE_NAME_PREFIX_LENGTH,
 
127
    return((uint) (strmake(to, from+MYSQL50_TABLE_NAME_PREFIX_LENGTH,
133
128
                                to_length-1) -
134
129
                        (from + MYSQL50_TABLE_NAME_PREFIX_LENGTH)));
135
130
  length= strconvert(system_charset_info, from,
140
135
    memcpy(to + length, "@@@", 4);
141
136
    length+= 3;
142
137
  }
143
 
  DBUG_PRINT("exit", ("to '%s'", to));
144
 
  DBUG_RETURN(length);
 
138
  return(length);
145
139
}
146
140
 
147
141
 
183
177
{
184
178
  char dbbuff[FN_REFLEN];
185
179
  char tbbuff[FN_REFLEN];
186
 
  DBUG_ENTER("build_table_filename");
187
 
  DBUG_PRINT("enter", ("db: '%s'  table_name: '%s'  ext: '%s'  flags: %x",
188
 
                       db, table_name, ext, flags));
189
180
 
190
181
  if (flags & FN_IS_TMP) // FN_FROM_IS_TMP | FN_TO_IS_TMP
191
182
    strnmov(tbbuff, table_name, sizeof(tbbuff));
208
199
#endif
209
200
  pos= strxnmov(pos, end - pos, tbbuff, ext, NullS);
210
201
 
211
 
  DBUG_PRINT("exit", ("buff: '%s'", buff));
212
 
  DBUG_RETURN(pos - buff);
 
202
  return(pos - buff);
213
203
}
214
204
 
215
205
 
233
223
 
234
224
uint build_tmptable_filename(THD* thd, char *buff, size_t bufflen)
235
225
{
236
 
  DBUG_ENTER("build_tmptable_filename");
237
226
 
238
227
  char *p= strnmov(buff, mysql_tmpdir, bufflen);
239
 
  my_snprintf(p, bufflen - (p - buff), "/%s%lx_%lx_%x%s",
 
228
  snprintf(p, bufflen - (p - buff), "/%s%lx_%lx_%x%s",
240
229
              tmp_file_prefix, current_pid,
241
230
              thd->thread_id, thd->tmp_table++, reg_ext);
242
231
 
247
236
  }
248
237
 
249
238
  uint length= unpack_filename(buff, buff);
250
 
  DBUG_PRINT("exit", ("buff: '%s'", buff));
251
 
  DBUG_RETURN(length);
 
239
  return(length);
252
240
}
253
241
 
254
242
/*
321
309
    read_ddl_log_file_entry()
322
310
    entry_no                     Entry number to read
323
311
  RETURN VALUES
324
 
    TRUE                         Error
325
 
    FALSE                        Success
 
312
    true                         Error
 
313
    false                        Success
326
314
*/
327
315
 
328
316
static bool read_ddl_log_file_entry(uint entry_no)
329
317
{
330
 
  bool error= FALSE;
 
318
  bool error= false;
331
319
  File file_id= global_ddl_log.file_id;
332
320
  uchar *file_entry_buf= (uchar*)global_ddl_log.file_entry_buf;
333
 
  uint io_size= global_ddl_log.io_size;
334
 
  DBUG_ENTER("read_ddl_log_file_entry");
335
 
 
 
321
  ssize_t io_size= (ssize_t)global_ddl_log.io_size;
 
322
  
336
323
  if (pread(file_id, file_entry_buf, io_size, io_size * entry_no) != io_size)
337
 
    error= TRUE;
338
 
  DBUG_RETURN(error);
 
324
    error= true;
 
325
  return(error);
339
326
}
340
327
 
341
328
 
345
332
    write_ddl_log_file_entry()
346
333
    entry_no                     Entry number to read
347
334
  RETURN VALUES
348
 
    TRUE                         Error
349
 
    FALSE                        Success
 
335
    true                         Error
 
336
    false                        Success
350
337
*/
351
338
 
352
339
static bool write_ddl_log_file_entry(uint entry_no)
353
340
{
354
 
  bool error= FALSE;
 
341
  bool error= false;
355
342
  File file_id= global_ddl_log.file_id;
356
343
  char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
357
 
  DBUG_ENTER("write_ddl_log_file_entry");
358
344
 
359
345
  if (pwrite(file_id, (uchar*)file_entry_buf,
360
 
             IO_SIZE, IO_SIZE * entry_no) != IO_SIZE)
361
 
    error= TRUE;
362
 
  DBUG_RETURN(error);
 
346
                IO_SIZE, IO_SIZE * entry_no) != IO_SIZE)
 
347
    error= true;
 
348
  return(error);
363
349
}
364
350
 
365
351
 
368
354
  SYNOPSIS
369
355
    write_ddl_log_header()
370
356
  RETURN VALUES
371
 
    TRUE                      Error
372
 
    FALSE                     Success
 
357
    true                      Error
 
358
    false                     Success
373
359
*/
374
360
 
375
361
static bool write_ddl_log_header()
376
362
{
377
363
  uint16 const_var;
378
 
  bool error= FALSE;
379
 
  DBUG_ENTER("write_ddl_log_header");
 
364
  bool error= false;
380
365
 
381
366
  int4store(&global_ddl_log.file_entry_buf[DDL_LOG_NUM_ENTRY_POS],
382
367
            global_ddl_log.num_entries);
389
374
  if (write_ddl_log_file_entry(0UL))
390
375
  {
391
376
    sql_print_error("Error writing ddl log header");
392
 
    DBUG_RETURN(TRUE);
 
377
    return(true);
393
378
  }
394
379
  VOID(sync_ddl_log());
395
 
  DBUG_RETURN(error);
 
380
  return(error);
396
381
}
397
382
 
398
383
 
429
414
  char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
430
415
  char file_name[FN_REFLEN];
431
416
  uint entry_no;
432
 
  bool successful_open= FALSE;
433
 
  DBUG_ENTER("read_ddl_log_header");
 
417
  bool successful_open= false;
434
418
 
435
419
  create_ddl_log_file_name(file_name);
436
420
  if ((global_ddl_log.file_id= my_open(file_name,
442
426
      sql_print_error("Failed to read ddl log file in recovery");
443
427
    }
444
428
    else
445
 
      successful_open= TRUE;
 
429
      successful_open= true;
446
430
  }
447
431
  entry_no= uint4korr(&file_entry_buf[DDL_LOG_NUM_ENTRY_POS]);
448
432
  global_ddl_log.name_len= uint4korr(&file_entry_buf[DDL_LOG_NAME_LEN_POS]);
449
433
  if (successful_open)
450
434
  {
451
435
    global_ddl_log.io_size= uint4korr(&file_entry_buf[DDL_LOG_IO_SIZE_POS]);
452
 
    DBUG_ASSERT(global_ddl_log.io_size <=
 
436
    assert(global_ddl_log.io_size <=
453
437
                sizeof(global_ddl_log.file_entry_buf));
454
438
  }
455
439
  else
461
445
  global_ddl_log.num_entries= 0;
462
446
  VOID(pthread_mutex_init(&LOCK_gdl, MY_MUTEX_INIT_FAST));
463
447
  global_ddl_log.do_release= true;
464
 
  DBUG_RETURN(entry_no);
 
448
  return(entry_no);
465
449
}
466
450
 
467
451
 
472
456
    read_entry               Number of entry to read
473
457
    out:entry_info           Information from entry
474
458
  RETURN VALUES
475
 
    TRUE                     Error
476
 
    FALSE                    Success
 
459
    true                     Error
 
460
    false                    Success
477
461
  DESCRIPTION
478
462
    Read a specified entry in the ddl log
479
463
*/
483
467
  char *file_entry_buf= (char*)&global_ddl_log.file_entry_buf;
484
468
  uint inx;
485
469
  uchar single_char;
486
 
  DBUG_ENTER("read_ddl_log_entry");
487
470
 
488
471
  if (read_ddl_log_file_entry(read_entry))
489
472
  {
490
 
    DBUG_RETURN(TRUE);
 
473
    return(true);
491
474
  }
492
475
  ddl_log_entry->entry_pos= read_entry;
493
476
  single_char= file_entry_buf[DDL_LOG_ENTRY_TYPE_POS];
501
484
  ddl_log_entry->from_name= &file_entry_buf[inx];
502
485
  inx+= global_ddl_log.name_len;
503
486
  ddl_log_entry->handler_name= &file_entry_buf[inx];
504
 
  DBUG_RETURN(FALSE);
 
487
  return(false);
505
488
}
506
489
 
507
490
 
515
498
    number of entries to zero.
516
499
 
517
500
  RETURN VALUES
518
 
    TRUE                     Error
519
 
    FALSE                    Success
 
501
    true                     Error
 
502
    false                    Success
520
503
*/
521
504
 
522
505
static bool init_ddl_log()
523
506
{
524
507
  char file_name[FN_REFLEN];
525
 
  DBUG_ENTER("init_ddl_log");
526
508
 
527
509
  if (global_ddl_log.inited)
528
510
    goto end;
536
518
  {
537
519
    /* Couldn't create ddl log file, this is serious error */
538
520
    sql_print_error("Failed to open ddl log file");
539
 
    DBUG_RETURN(TRUE);
 
521
    return(true);
540
522
  }
541
 
  global_ddl_log.inited= TRUE;
 
523
  global_ddl_log.inited= true;
542
524
  if (write_ddl_log_header())
543
525
  {
544
526
    VOID(my_close(global_ddl_log.file_id, MYF(MY_WME)));
545
 
    global_ddl_log.inited= FALSE;
546
 
    DBUG_RETURN(TRUE);
 
527
    global_ddl_log.inited= false;
 
528
    return(true);
547
529
  }
548
530
 
549
531
end:
550
 
  DBUG_RETURN(FALSE);
 
532
  return(false);
551
533
}
552
534
 
553
535
 
557
539
    execute_ddl_log_action()
558
540
    ddl_log_entry              Information in action entry to execute
559
541
  RETURN VALUES
560
 
    TRUE                       Error
561
 
    FALSE                      Success
 
542
    true                       Error
 
543
    false                      Success
562
544
*/
563
545
 
564
546
static int execute_ddl_log_action(THD *thd, DDL_LOG_ENTRY *ddl_log_entry)
565
547
{
566
 
  bool frm_action= FALSE;
 
548
  bool frm_action= false;
567
549
  LEX_STRING handler_name;
568
550
  handler *file= NULL;
569
551
  MEM_ROOT mem_root;
570
 
  int error= TRUE;
 
552
  int error= true;
571
553
  char to_path[FN_REFLEN];
572
554
  char from_path[FN_REFLEN];
573
555
  handlerton *hton;
574
 
  DBUG_ENTER("execute_ddl_log_action");
575
556
 
576
557
  if (ddl_log_entry->entry_type == DDL_IGNORE_LOG_ENTRY_CODE)
577
558
  {
578
 
    DBUG_RETURN(FALSE);
 
559
    return(false);
579
560
  }
580
561
  handler_name.str= (char*)ddl_log_entry->handler_name;
581
562
  handler_name.length= strlen(ddl_log_entry->handler_name);
582
563
  init_sql_alloc(&mem_root, TABLE_ALLOC_BLOCK_SIZE, 0); 
583
564
  if (!strcmp(ddl_log_entry->handler_name, reg_ext))
584
 
    frm_action= TRUE;
 
565
    frm_action= true;
585
566
  else
586
567
  {
587
568
    plugin_ref plugin= ha_resolve_by_name(thd, &handler_name);
625
606
        if ((deactivate_ddl_log_entry(ddl_log_entry->entry_pos)))
626
607
          break;
627
608
        VOID(sync_ddl_log());
628
 
        error= FALSE;
 
609
        error= false;
629
610
        if (ddl_log_entry->action_type == DDL_LOG_DELETE_ACTION)
630
611
          break;
631
612
      }
632
 
      DBUG_ASSERT(ddl_log_entry->action_type == DDL_LOG_REPLACE_ACTION);
 
613
      assert(ddl_log_entry->action_type == DDL_LOG_REPLACE_ACTION);
633
614
      /*
634
615
        Fall through and perform the rename action of the replace
635
616
        action. We have already indicated the success of the delete
638
619
    }
639
620
    case DDL_LOG_RENAME_ACTION:
640
621
    {
641
 
      error= TRUE;
 
622
      error= true;
642
623
      if (frm_action)
643
624
      {
644
625
        strxmov(to_path, ddl_log_entry->name, reg_ext, NullS);
655
636
      if ((deactivate_ddl_log_entry(ddl_log_entry->entry_pos)))
656
637
        break;
657
638
      VOID(sync_ddl_log());
658
 
      error= FALSE;
 
639
      error= false;
659
640
      break;
660
641
    }
661
642
    default:
662
 
      DBUG_ASSERT(0);
 
643
      assert(0);
663
644
      break;
664
645
  }
665
646
  delete file;
666
647
error:
667
648
  free_root(&mem_root, MYF(0)); 
668
 
  DBUG_RETURN(error);
 
649
  return(error);
669
650
}
670
651
 
671
652
 
675
656
    get_free_ddl_log_entry()
676
657
    out:active_entry                A ddl log memory entry returned
677
658
  RETURN VALUES
678
 
    TRUE                       Error
679
 
    FALSE                      Success
 
659
    true                       Error
 
660
    false                      Success
680
661
*/
681
662
 
682
663
static bool get_free_ddl_log_entry(DDL_LOG_MEMORY_ENTRY **active_entry,
684
665
{
685
666
  DDL_LOG_MEMORY_ENTRY *used_entry;
686
667
  DDL_LOG_MEMORY_ENTRY *first_used= global_ddl_log.first_used;
687
 
  DBUG_ENTER("get_free_ddl_log_entry");
688
668
 
689
669
  if (global_ddl_log.first_free == NULL)
690
670
  {
692
672
                              sizeof(DDL_LOG_MEMORY_ENTRY), MYF(MY_WME))))
693
673
    {
694
674
      sql_print_error("Failed to allocate memory for ddl log free list");
695
 
      DBUG_RETURN(TRUE);
 
675
      return(true);
696
676
    }
697
677
    global_ddl_log.num_entries++;
698
678
    used_entry->entry_pos= global_ddl_log.num_entries;
699
 
    *write_header= TRUE;
 
679
    *write_header= true;
700
680
  }
701
681
  else
702
682
  {
703
683
    used_entry= global_ddl_log.first_free;
704
684
    global_ddl_log.first_free= used_entry->next_log_entry;
705
 
    *write_header= FALSE;
 
685
    *write_header= false;
706
686
  }
707
687
  /*
708
688
    Move from free list to used list
714
694
    first_used->prev_log_entry= used_entry;
715
695
 
716
696
  *active_entry= used_entry;
717
 
  DBUG_RETURN(FALSE);
 
697
  return(false);
718
698
}
719
699
 
720
700
 
730
710
    out:entry_written     Entry information written into   
731
711
 
732
712
  RETURN VALUES
733
 
    TRUE                      Error
734
 
    FALSE                     Success
 
713
    true                      Error
 
714
    false                     Success
735
715
 
736
716
  DESCRIPTION
737
717
    A careful write of the ddl log is performed to ensure that we can
742
722
                         DDL_LOG_MEMORY_ENTRY **active_entry)
743
723
{
744
724
  bool error, write_header;
745
 
  DBUG_ENTER("write_ddl_log_entry");
746
725
 
747
726
  if (init_ddl_log())
748
727
  {
749
 
    DBUG_RETURN(TRUE);
 
728
    return(true);
750
729
  }
751
730
  global_ddl_log.file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]=
752
731
                                    (char)DDL_LOG_ENTRY_CODE;
755
734
  global_ddl_log.file_entry_buf[DDL_LOG_PHASE_POS]= 0;
756
735
  int4store(&global_ddl_log.file_entry_buf[DDL_LOG_NEXT_ENTRY_POS],
757
736
            ddl_log_entry->next_entry);
758
 
  DBUG_ASSERT(strlen(ddl_log_entry->name) < FN_LEN);
 
737
  assert(strlen(ddl_log_entry->name) < FN_LEN);
759
738
  strmake(&global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS],
760
739
          ddl_log_entry->name, FN_LEN - 1);
761
740
  if (ddl_log_entry->action_type == DDL_LOG_RENAME_ACTION ||
762
741
      ddl_log_entry->action_type == DDL_LOG_REPLACE_ACTION)
763
742
  {
764
 
    DBUG_ASSERT(strlen(ddl_log_entry->from_name) < FN_LEN);
 
743
    assert(strlen(ddl_log_entry->from_name) < FN_LEN);
765
744
    strmake(&global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS + FN_LEN],
766
745
          ddl_log_entry->from_name, FN_LEN - 1);
767
746
  }
768
747
  else
769
748
    global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS + FN_LEN]= 0;
770
 
  DBUG_ASSERT(strlen(ddl_log_entry->handler_name) < FN_LEN);
 
749
  assert(strlen(ddl_log_entry->handler_name) < FN_LEN);
771
750
  strmake(&global_ddl_log.file_entry_buf[DDL_LOG_NAME_POS + (2*FN_LEN)],
772
751
          ddl_log_entry->handler_name, FN_LEN - 1);
773
752
  if (get_free_ddl_log_entry(active_entry, &write_header))
774
753
  {
775
 
    DBUG_RETURN(TRUE);
 
754
    return(true);
776
755
  }
777
 
  error= FALSE;
 
756
  error= false;
778
757
  if (write_ddl_log_file_entry((*active_entry)->entry_pos))
779
758
  {
780
 
    error= TRUE;
 
759
    error= true;
781
760
    sql_print_error("Failed to write entry_no = %u",
782
761
                    (*active_entry)->entry_pos);
783
762
  }
785
764
  {
786
765
    VOID(sync_ddl_log());
787
766
    if (write_ddl_log_header())
788
 
      error= TRUE;
 
767
      error= true;
789
768
  }
790
769
  if (error)
791
770
    release_ddl_log_memory_entry(*active_entry);
792
 
  DBUG_RETURN(error);
 
771
  return(error);
793
772
}
794
773
 
795
774
 
808
787
                                   returned. In this case the entry written
809
788
                                   is returned in this parameter
810
789
  RETURN VALUES
811
 
    TRUE                           Error
812
 
    FALSE                          Success
 
790
    true                           Error
 
791
    false                          Success
813
792
 
814
793
  DESCRIPTION
815
794
    This is the last write in the ddl log. The previous log entries have
824
803
                                 bool complete,
825
804
                                 DDL_LOG_MEMORY_ENTRY **active_entry)
826
805
{
827
 
  bool write_header= FALSE;
 
806
  bool write_header= false;
828
807
  char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
829
 
  DBUG_ENTER("write_execute_ddl_log_entry");
830
808
 
831
809
  if (init_ddl_log())
832
810
  {
833
 
    DBUG_RETURN(TRUE);
 
811
    return(true);
834
812
  }
835
813
  if (!complete)
836
814
  {
855
833
  {
856
834
    if (get_free_ddl_log_entry(active_entry, &write_header))
857
835
    {
858
 
      DBUG_RETURN(TRUE);
 
836
      return(true);
859
837
    }
860
838
  }
861
839
  if (write_ddl_log_file_entry((*active_entry)->entry_pos))
862
840
  {
863
841
    sql_print_error("Error writing execute entry in ddl log");
864
842
    release_ddl_log_memory_entry(*active_entry);
865
 
    DBUG_RETURN(TRUE);
 
843
    return(true);
866
844
  }
867
845
  VOID(sync_ddl_log());
868
846
  if (write_header)
870
848
    if (write_ddl_log_header())
871
849
    {
872
850
      release_ddl_log_memory_entry(*active_entry);
873
 
      DBUG_RETURN(TRUE);
 
851
      return(true);
874
852
    }
875
853
  }
876
 
  DBUG_RETURN(FALSE);
 
854
  return(false);
877
855
}
878
856
 
879
857
 
883
861
    deactivate_ddl_log_entry()
884
862
    entry_no                      Entry position of record to change
885
863
  RETURN VALUES
886
 
    TRUE                         Error
887
 
    FALSE                        Success
 
864
    true                         Error
 
865
    false                        Success
888
866
  DESCRIPTION
889
867
    During replace operations where we start with an existing table called
890
868
    t1 and a replacement table called t1#temp or something else and where
904
882
bool deactivate_ddl_log_entry(uint entry_no)
905
883
{
906
884
  char *file_entry_buf= (char*)global_ddl_log.file_entry_buf;
907
 
  DBUG_ENTER("deactivate_ddl_log_entry");
908
885
 
909
886
  if (!read_ddl_log_file_entry(entry_no))
910
887
  {
917
894
        file_entry_buf[DDL_LOG_ENTRY_TYPE_POS]= DDL_IGNORE_LOG_ENTRY_CODE;
918
895
      else if (file_entry_buf[DDL_LOG_ACTION_TYPE_POS] == DDL_LOG_REPLACE_ACTION)
919
896
      {
920
 
        DBUG_ASSERT(file_entry_buf[DDL_LOG_PHASE_POS] == 0);
 
897
        assert(file_entry_buf[DDL_LOG_PHASE_POS] == 0);
921
898
        file_entry_buf[DDL_LOG_PHASE_POS]= 1;
922
899
      }
923
900
      else
924
901
      {
925
 
        DBUG_ASSERT(0);
 
902
        assert(0);
926
903
      }
927
904
      if (write_ddl_log_file_entry(entry_no))
928
905
      {
929
906
        sql_print_error("Error in deactivating log entry. Position = %u",
930
907
                        entry_no);
931
 
        DBUG_RETURN(TRUE);
 
908
        return(true);
932
909
      }
933
910
    }
934
911
  }
935
912
  else
936
913
  {
937
914
    sql_print_error("Failed in reading entry before deactivating it");
938
 
    DBUG_RETURN(TRUE);
 
915
    return(true);
939
916
  }
940
 
  DBUG_RETURN(FALSE);
 
917
  return(false);
941
918
}
942
919
 
943
920
 
946
923
  SYNOPSIS
947
924
    sync_ddl_log()
948
925
  RETURN VALUES
949
 
    TRUE                      Error
950
 
    FALSE                     Success
 
926
    true                      Error
 
927
    false                     Success
951
928
*/
952
929
 
953
930
bool sync_ddl_log()
954
931
{
955
 
  bool error= FALSE;
956
 
  DBUG_ENTER("sync_ddl_log");
 
932
  bool error= false;
957
933
 
958
934
  if ((!global_ddl_log.recovery_phase) &&
959
935
      init_ddl_log())
960
936
  {
961
 
    DBUG_RETURN(TRUE);
 
937
    return(true);
962
938
  }
963
939
  if (my_sync(global_ddl_log.file_id, MYF(0)))
964
940
  {
965
941
    /* Write to error log */
966
942
    sql_print_error("Failed to sync ddl log");
967
 
    error= TRUE;
 
943
    error= true;
968
944
  }
969
 
  DBUG_RETURN(error);
 
945
  return(error);
970
946
}
971
947
 
972
948
 
984
960
  DDL_LOG_MEMORY_ENTRY *first_free= global_ddl_log.first_free;
985
961
  DDL_LOG_MEMORY_ENTRY *next_log_entry= log_entry->next_log_entry;
986
962
  DDL_LOG_MEMORY_ENTRY *prev_log_entry= log_entry->prev_log_entry;
987
 
  DBUG_ENTER("release_ddl_log_memory_entry");
988
963
 
989
964
  global_ddl_log.first_free= log_entry;
990
965
  log_entry->next_log_entry= first_free;
995
970
    global_ddl_log.first_used= next_log_entry;
996
971
  if (next_log_entry)
997
972
    next_log_entry->prev_log_entry= prev_log_entry;
998
 
  DBUG_VOID_RETURN;
 
973
  return;
999
974
}
1000
975
 
1001
976
 
1006
981
    execute_ddl_log_entry()
1007
982
    first_entry                Reference to first action in entry
1008
983
  RETURN VALUES
1009
 
    TRUE                       Error
1010
 
    FALSE                      Success
 
984
    true                       Error
 
985
    false                      Success
1011
986
*/
1012
987
 
1013
988
bool execute_ddl_log_entry(THD *thd, uint first_entry)
1014
989
{
1015
990
  DDL_LOG_ENTRY ddl_log_entry;
1016
991
  uint read_entry= first_entry;
1017
 
  DBUG_ENTER("execute_ddl_log_entry");
1018
992
 
1019
993
  pthread_mutex_lock(&LOCK_gdl);
1020
994
  do
1026
1000
                      read_entry);
1027
1001
      break;
1028
1002
    }
1029
 
    DBUG_ASSERT(ddl_log_entry.entry_type == DDL_LOG_ENTRY_CODE ||
 
1003
    assert(ddl_log_entry.entry_type == DDL_LOG_ENTRY_CODE ||
1030
1004
                ddl_log_entry.entry_type == DDL_IGNORE_LOG_ENTRY_CODE);
1031
1005
 
1032
1006
    if (execute_ddl_log_action(thd, &ddl_log_entry))
1039
1013
    read_entry= ddl_log_entry.next_entry;
1040
1014
  } while (read_entry);
1041
1015
  pthread_mutex_unlock(&LOCK_gdl);
1042
 
  DBUG_RETURN(FALSE);
 
1016
  return(false);
1043
1017
}
1044
1018
 
1045
1019
 
1053
1027
 
1054
1028
static void close_ddl_log()
1055
1029
{
1056
 
  DBUG_ENTER("close_ddl_log");
1057
1030
  if (global_ddl_log.file_id >= 0)
1058
1031
  {
1059
1032
    VOID(my_close(global_ddl_log.file_id, MYF(MY_WME)));
1060
1033
    global_ddl_log.file_id= (File) -1;
1061
1034
  }
1062
 
  DBUG_VOID_RETURN;
 
1035
  return;
1063
1036
}
1064
1037
 
1065
1038
 
1077
1050
  THD *thd;
1078
1051
  DDL_LOG_ENTRY ddl_log_entry;
1079
1052
  char file_name[FN_REFLEN];
1080
 
  DBUG_ENTER("execute_ddl_log_recovery");
1081
1053
 
1082
1054
  /*
1083
1055
    Initialise global_ddl_log struct
1084
1056
  */
1085
1057
  bzero(global_ddl_log.file_entry_buf, sizeof(global_ddl_log.file_entry_buf));
1086
 
  global_ddl_log.inited= FALSE;
1087
 
  global_ddl_log.recovery_phase= TRUE;
 
1058
  global_ddl_log.inited= false;
 
1059
  global_ddl_log.recovery_phase= true;
1088
1060
  global_ddl_log.io_size= IO_SIZE;
1089
1061
  global_ddl_log.file_id= (File) -1;
1090
1062
 
1092
1064
    To be able to run this from boot, we allocate a temporary THD
1093
1065
  */
1094
1066
  if (!(thd=new THD))
1095
 
    DBUG_VOID_RETURN;
 
1067
    return;
1096
1068
  thd->thread_stack= (char*) &thd;
1097
1069
  thd->store_globals();
1098
1070
 
1117
1089
  close_ddl_log();
1118
1090
  create_ddl_log_file_name(file_name);
1119
1091
  VOID(my_delete(file_name, MYF(0)));
1120
 
  global_ddl_log.recovery_phase= FALSE;
 
1092
  global_ddl_log.recovery_phase= false;
1121
1093
  delete thd;
1122
1094
  /* Remember that we don't have a THD */
1123
1095
  my_pthread_setspecific_ptr(THR_THD,  0);
1124
 
  DBUG_VOID_RETURN;
 
1096
  return;
1125
1097
}
1126
1098
 
1127
1099
 
1137
1109
{
1138
1110
  DDL_LOG_MEMORY_ENTRY *free_list= global_ddl_log.first_free;
1139
1111
  DDL_LOG_MEMORY_ENTRY *used_list= global_ddl_log.first_used;
1140
 
  DBUG_ENTER("release_ddl_log");
1141
1112
 
1142
1113
  if (!global_ddl_log.do_release)
1143
 
    DBUG_VOID_RETURN;
 
1114
    return;
1144
1115
 
1145
1116
  pthread_mutex_lock(&LOCK_gdl);
1146
1117
  while (used_list)
1160
1131
  pthread_mutex_unlock(&LOCK_gdl);
1161
1132
  VOID(pthread_mutex_destroy(&LOCK_gdl));
1162
1133
  global_ddl_log.do_release= false;
1163
 
  DBUG_VOID_RETURN;
 
1134
  return;
1164
1135
}
1165
1136
 
1166
1137
 
1198
1169
    if (clear_error)
1199
1170
      thd->clear_error();
1200
1171
    thd->binlog_query(THD::STMT_QUERY_TYPE,
1201
 
                      query, query_length, FALSE, FALSE);
 
1172
                      query, query_length, false, false);
1202
1173
  }
1203
1174
}
1204
1175
 
1222
1193
    not if under LOCK TABLES.
1223
1194
 
1224
1195
  RETURN
1225
 
    FALSE OK.  In this case ok packet is sent to user
1226
 
    TRUE  Error
 
1196
    false OK.  In this case ok packet is sent to user
 
1197
    true  Error
1227
1198
 
1228
1199
*/
1229
1200
 
1230
1201
bool mysql_rm_table(THD *thd,TABLE_LIST *tables, my_bool if_exists,
1231
1202
                    my_bool drop_temporary)
1232
1203
{
1233
 
  bool error, need_start_waiting= FALSE;
1234
 
  DBUG_ENTER("mysql_rm_table");
 
1204
  bool error, need_start_waiting= false;
1235
1205
 
1236
1206
  if (tables && tables->schema_table)
1237
1207
  {
1238
1208
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
1239
 
    DBUG_RETURN(TRUE);
 
1209
    return(true);
1240
1210
  }
1241
1211
 
1242
1212
  /* mark for close and remove all cached entries */
1245
1215
  {
1246
1216
    if (!thd->locked_tables &&
1247
1217
        !(need_start_waiting= !wait_if_global_read_lock(thd, 0, 1)))
1248
 
      DBUG_RETURN(TRUE);
 
1218
      return(true);
1249
1219
  }
1250
1220
 
1251
1221
  /*
1259
1229
    start_waiting_global_read_lock(thd);
1260
1230
 
1261
1231
  if (error)
1262
 
    DBUG_RETURN(TRUE);
 
1232
    return(true);
1263
1233
  my_ok(thd);
1264
 
  DBUG_RETURN(FALSE);
 
1234
  return(false);
1265
1235
}
1266
1236
 
1267
1237
/*
1306
1276
  int non_temp_tables_count= 0;
1307
1277
  bool some_tables_deleted=0, tmp_table_deleted=0, foreign_key_error=0;
1308
1278
  String built_query;
1309
 
  DBUG_ENTER("mysql_rm_table_part2");
1310
1279
 
1311
1280
  if (thd->current_stmt_binlog_row_based && !dont_log_query)
1312
1281
  {
1317
1286
      built_query.append("DROP TABLE ");
1318
1287
  }
1319
1288
 
1320
 
  mysql_ha_rm_tables(thd, tables, FALSE);
 
1289
  mysql_ha_rm_tables(thd, tables, false);
1321
1290
 
1322
1291
  pthread_mutex_lock(&LOCK_open);
1323
1292
 
1338
1307
  if (!drop_temporary && lock_table_names_exclusively(thd, tables))
1339
1308
  {
1340
1309
    pthread_mutex_unlock(&LOCK_open);
1341
 
    DBUG_RETURN(1);
 
1310
    return(1);
1342
1311
  }
1343
1312
 
1344
1313
  /* Don't give warnings for not found errors, as we already generate notes */
1350
1319
    handlerton *table_type;
1351
1320
    enum legacy_db_type frm_db_type;
1352
1321
 
1353
 
    DBUG_PRINT("table", ("table_l: '%s'.'%s'  table: 0x%lx  s: 0x%lx",
1354
 
                         table->db, table->table_name, (long) table->table,
1355
 
                         table->table ? (long) table->table->s : (long) -1));
1356
1322
 
1357
1323
    error= drop_temporary_table(thd, table);
1358
1324
 
1362
1328
      tmp_table_deleted= 1;
1363
1329
      continue;
1364
1330
    case -1:
1365
 
      DBUG_ASSERT(thd->in_sub_stmt);
 
1331
      assert(thd->in_sub_stmt);
1366
1332
      error= 1;
1367
1333
      goto err_with_placeholders;
1368
1334
    default:
1474
1440
        wrong_tables.append(',');
1475
1441
      wrong_tables.append(String(table->table_name,system_charset_info));
1476
1442
    }
1477
 
    DBUG_PRINT("table", ("table: 0x%lx  s: 0x%lx", (long) table->table,
1478
 
                         table->table ? (long) table->table->s : (long) -1));
1479
1443
  }
1480
1444
  /*
1481
1445
    It's safe to unlock LOCK_open: we have an exclusive lock
1545
1509
  unlock_table_names(thd, tables, (TABLE_LIST*) 0);
1546
1510
  pthread_mutex_unlock(&LOCK_open);
1547
1511
  thd->no_warnings_for_error= 0;
1548
 
  DBUG_RETURN(error);
 
1512
  return(error);
1549
1513
}
1550
1514
 
1551
1515
 
1569
1533
{
1570
1534
  char path[FN_REFLEN];
1571
1535
  bool error= 0;
1572
 
  DBUG_ENTER("quick_rm_table");
1573
1536
 
1574
1537
  uint path_length= build_table_filename(path, sizeof(path),
1575
1538
                                         db, table_name, reg_ext, flags);
1576
1539
  if (my_delete(path,MYF(0)))
1577
1540
    error= 1; /* purecov: inspected */
1578
1541
  path[path_length - reg_ext_length]= '\0'; // Remove reg_ext
1579
 
  DBUG_RETURN(ha_delete_table(current_thd, base, path, db, table_name, 0) ||
 
1542
  return(ha_delete_table(current_thd, base, path, db, table_name, 0) ||
1580
1543
              error);
1581
1544
}
1582
1545
 
1601
1564
  {
1602
1565
    if (!(b_flags & HA_NOSAME))
1603
1566
      return -1;
1604
 
    if ((a_flags ^ b_flags) & (HA_NULL_PART_KEY | HA_END_SPACE_KEY))
 
1567
    if ((a_flags ^ b_flags) & (HA_NULL_PART_KEY))
1605
1568
    {
1606
1569
      /* Sort NOT NULL keys before other keys */
1607
 
      return (a_flags & (HA_NULL_PART_KEY | HA_END_SPACE_KEY)) ? 1 : -1;
 
1570
      return (a_flags & (HA_NULL_PART_KEY)) ? 1 : -1;
1608
1571
    }
1609
1572
    if (a->name == primary_key_name)
1610
1573
      return -1;
1726
1689
int prepare_create_field(Create_field *sql_field, 
1727
1690
                         uint *blob_columns,
1728
1691
                         int *timestamps, int *timestamps_with_niladic,
1729
 
                         longlong table_flags)
 
1692
                         longlong table_flags __attribute__((__unused__)))
1730
1693
{
1731
1694
  unsigned int dup_val_count;
1732
 
  DBUG_ENTER("prepare_field");
1733
1695
 
1734
1696
  /*
1735
1697
    This code came from mysql_prepare_create_table.
1736
1698
    Indent preserved to make patching easier
1737
1699
  */
1738
 
  DBUG_ASSERT(sql_field->charset);
 
1700
  assert(sql_field->charset);
1739
1701
 
1740
1702
  switch (sql_field->sql_type) {
1741
1703
  case MYSQL_TYPE_BLOB:
1752
1714
    (*blob_columns)++;
1753
1715
    break;
1754
1716
  case MYSQL_TYPE_VARCHAR:
1755
 
#ifndef QQ_ALL_HANDLERS_SUPPORT_VARCHAR
1756
 
    if (table_flags & HA_NO_VARCHAR)
1757
 
    {
1758
 
      /* convert VARCHAR to CHAR because handler is not yet up to date */
1759
 
      sql_field->sql_type=    MYSQL_TYPE_VAR_STRING;
1760
 
      sql_field->pack_length= calc_pack_length(sql_field->sql_type,
1761
 
                                               (uint) sql_field->length);
1762
 
      if ((sql_field->length / sql_field->charset->mbmaxlen) >
1763
 
          MAX_FIELD_CHARLENGTH)
1764
 
      {
1765
 
        my_printf_error(ER_TOO_BIG_FIELDLENGTH, ER(ER_TOO_BIG_FIELDLENGTH),
1766
 
                        MYF(0), sql_field->field_name, MAX_FIELD_CHARLENGTH);
1767
 
        DBUG_RETURN(1);
1768
 
      }
1769
 
    }
1770
 
#endif
1771
 
    /* fall through */
1772
1717
  case MYSQL_TYPE_STRING:
1773
1718
    sql_field->pack_flag=0;
1774
1719
    if (sql_field->charset->state & MY_CS_BINSORT)
1783
1728
    if (check_duplicates_in_interval("ENUM",sql_field->field_name,
1784
1729
                                 sql_field->interval,
1785
1730
                                     sql_field->charset, &dup_val_count))
1786
 
      DBUG_RETURN(1);
 
1731
      return(1);
1787
1732
    break;
1788
1733
  case MYSQL_TYPE_SET:
1789
1734
    sql_field->pack_flag=pack_length_to_packflag(sql_field->pack_length) |
1794
1739
    if (check_duplicates_in_interval("SET",sql_field->field_name,
1795
1740
                                 sql_field->interval,
1796
1741
                                     sql_field->charset, &dup_val_count))
1797
 
      DBUG_RETURN(1);
 
1742
      return(1);
1798
1743
    /* Check that count of unique members is not more then 64 */
1799
1744
    if (sql_field->interval->count -  dup_val_count > sizeof(longlong)*8)
1800
1745
    {
1801
1746
       my_error(ER_TOO_BIG_SET, MYF(0), sql_field->field_name);
1802
 
       DBUG_RETURN(1);
 
1747
       return(1);
1803
1748
    }
1804
1749
    break;
1805
 
  case MYSQL_TYPE_DATE:                 // Rest of string types
1806
 
  case MYSQL_TYPE_NEWDATE:
 
1750
  case MYSQL_TYPE_NEWDATE:  // Rest of string types
1807
1751
  case MYSQL_TYPE_TIME:
1808
1752
  case MYSQL_TYPE_DATETIME:
1809
1753
  case MYSQL_TYPE_NULL:
1810
1754
    sql_field->pack_flag=f_settype((uint) sql_field->sql_type);
1811
1755
    break;
1812
 
  case MYSQL_TYPE_BIT:
1813
 
    /* 
1814
 
      We have sql_field->pack_flag already set here, see
1815
 
      mysql_prepare_create_table().
1816
 
    */
1817
 
    break;
1818
1756
  case MYSQL_TYPE_NEWDECIMAL:
1819
1757
    sql_field->pack_flag=(FIELDFLAG_NUMBER |
1820
1758
                          (sql_field->flags & UNSIGNED_FLAG ? 0 :
1854
1792
    sql_field->pack_flag|= FIELDFLAG_MAYBE_NULL;
1855
1793
  if (sql_field->flags & NO_DEFAULT_VALUE_FLAG)
1856
1794
    sql_field->pack_flag|= FIELDFLAG_NO_DEFAULT;
1857
 
  DBUG_RETURN(0);
 
1795
  return(0);
1858
1796
}
1859
1797
 
1860
1798
/*
1879
1817
    sets create_info->varchar if the table has a varchar
1880
1818
 
1881
1819
  RETURN VALUES
1882
 
    FALSE    OK
1883
 
    TRUE     error
 
1820
    false    OK
 
1821
    true     error
1884
1822
*/
1885
1823
 
1886
1824
static int
1903
1841
  List_iterator<Create_field> it(alter_info->create_list);
1904
1842
  List_iterator<Create_field> it2(alter_info->create_list);
1905
1843
  uint total_uneven_bit_length= 0;
1906
 
  DBUG_ENTER("mysql_prepare_create_table");
1907
1844
 
1908
1845
  select_field_pos= alter_info->create_list.elements - select_field_count;
1909
1846
  null_fields=blob_columns=0;
1940
1877
      strmake(strmake(tmp, save_cs->csname, sizeof(tmp)-4),
1941
1878
              STRING_WITH_LEN("_bin"));
1942
1879
      my_error(ER_UNKNOWN_COLLATION, MYF(0), tmp);
1943
 
      DBUG_RETURN(TRUE);
 
1880
      return(true);
1944
1881
    }
1945
1882
 
1946
1883
    /*
1970
1907
      {
1971
1908
        /* Could not convert */
1972
1909
        my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
1973
 
        DBUG_RETURN(TRUE);
 
1910
        return(true);
1974
1911
      }
1975
1912
    }
1976
1913
 
2001
1938
        int comma_length= cs->cset->wc_mb(cs, ',', (uchar*) comma_buf,
2002
1939
                                          (uchar*) comma_buf + 
2003
1940
                                          sizeof(comma_buf));
2004
 
        DBUG_ASSERT(comma_length > 0);
 
1941
        assert(comma_length > 0);
2005
1942
        for (uint i= 0; (tmp= int_it++); i++)
2006
1943
        {
2007
1944
          uint lengthsp;
2027
1964
                                comma_buf, comma_length, NULL, 0))
2028
1965
            {
2029
1966
              my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0), "set", tmp->ptr());
2030
 
              DBUG_RETURN(TRUE);
 
1967
              return(true);
2031
1968
            }
2032
1969
          }
2033
1970
        }
2048
1985
            if ((sql_field->flags & NOT_NULL_FLAG) != 0)
2049
1986
            {
2050
1987
              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
2051
 
              DBUG_RETURN(TRUE);
 
1988
              return(true);
2052
1989
            }
2053
1990
 
2054
1991
            /* else, NULL is an allowed value */
2064
2001
          if (not_found)
2065
2002
          {
2066
2003
            my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
2067
 
            DBUG_RETURN(TRUE);
 
2004
            return(true);
2068
2005
          }
2069
2006
        }
2070
2007
        calculate_interval_lengths(cs, interval, &dummy, &field_length);
2073
2010
      else  /* MYSQL_TYPE_ENUM */
2074
2011
      {
2075
2012
        uint32 field_length;
2076
 
        DBUG_ASSERT(sql_field->sql_type == MYSQL_TYPE_ENUM);
 
2013
        assert(sql_field->sql_type == MYSQL_TYPE_ENUM);
2077
2014
        if (sql_field->def != NULL)
2078
2015
        {
2079
2016
          String str, *def= sql_field->def->val_str(&str);
2082
2019
            if ((sql_field->flags & NOT_NULL_FLAG) != 0)
2083
2020
            {
2084
2021
              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
2085
 
              DBUG_RETURN(TRUE);
 
2022
              return(true);
2086
2023
            }
2087
2024
 
2088
2025
            /* else, the defaults yield the correct length for NULLs. */
2093
2030
            if (find_type2(interval, def->ptr(), def->length(), cs) == 0) /* not found */
2094
2031
            {
2095
2032
              my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
2096
 
              DBUG_RETURN(TRUE);
 
2033
              return(true);
2097
2034
            }
2098
2035
          }
2099
2036
        }
2103
2040
      set_if_smaller(sql_field->length, MAX_FIELD_WIDTH-1);
2104
2041
    }
2105
2042
 
2106
 
    if (sql_field->sql_type == MYSQL_TYPE_BIT)
2107
 
    { 
2108
 
      sql_field->pack_flag= FIELDFLAG_NUMBER;
2109
 
      if (file->ha_table_flags() & HA_CAN_BIT_FIELD)
2110
 
        total_uneven_bit_length+= sql_field->length & 7;
2111
 
      else
2112
 
        sql_field->pack_flag|= FIELDFLAG_TREAT_BIT_AS_CHAR;
2113
 
    }
2114
 
 
2115
2043
    sql_field->create_length_to_internal_length();
2116
2044
    if (prepare_blob_field(thd, sql_field))
2117
 
      DBUG_RETURN(TRUE);
 
2045
      return(true);
2118
2046
 
2119
2047
    if (!(sql_field->flags & NOT_NULL_FLAG))
2120
2048
      null_fields++;
2122
2050
    if (check_column_name(sql_field->field_name))
2123
2051
    {
2124
2052
      my_error(ER_WRONG_COLUMN_NAME, MYF(0), sql_field->field_name);
2125
 
      DBUG_RETURN(TRUE);
 
2053
      return(true);
2126
2054
    }
2127
2055
 
2128
2056
    /* Check if we have used the same field name before */
2139
2067
        if (field_no < select_field_pos || dup_no >= select_field_pos)
2140
2068
        {
2141
2069
          my_error(ER_DUP_FIELDNAME, MYF(0), sql_field->field_name);
2142
 
          DBUG_RETURN(TRUE);
 
2070
          return(true);
2143
2071
        }
2144
2072
        else
2145
2073
        {
2184
2112
  it.rewind();
2185
2113
  while ((sql_field=it++))
2186
2114
  {
2187
 
    DBUG_ASSERT(sql_field->charset != 0);
 
2115
    assert(sql_field->charset != 0);
2188
2116
 
2189
2117
    if (prepare_create_field(sql_field, &blob_columns, 
2190
2118
                             &timestamps, &timestamps_with_niladic,
2191
2119
                             file->ha_table_flags()))
2192
 
      DBUG_RETURN(TRUE);
 
2120
      return(true);
2193
2121
    if (sql_field->sql_type == MYSQL_TYPE_VARCHAR)
2194
 
      create_info->varchar= TRUE;
 
2122
      create_info->varchar= true;
2195
2123
    sql_field->offset= record_offset;
2196
2124
    if (MTYP_TYPENR(sql_field->unireg_check) == Field::NEXT_NUMBER)
2197
2125
      auto_increment++;
2201
2129
  {
2202
2130
    my_message(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS,
2203
2131
               ER(ER_TOO_MUCH_AUTO_TIMESTAMP_COLS), MYF(0));
2204
 
    DBUG_RETURN(TRUE);
 
2132
    return(true);
2205
2133
  }
2206
2134
  if (auto_increment > 1)
2207
2135
  {
2208
2136
    my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0));
2209
 
    DBUG_RETURN(TRUE);
 
2137
    return(true);
2210
2138
  }
2211
2139
  if (auto_increment &&
2212
2140
      (file->ha_table_flags() & HA_NO_AUTO_INCREMENT))
2213
2141
  {
2214
2142
    my_message(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT,
2215
2143
               ER(ER_TABLE_CANT_HANDLE_AUTO_INCREMENT), MYF(0));
2216
 
    DBUG_RETURN(TRUE);
 
2144
    return(true);
2217
2145
  }
2218
2146
 
2219
2147
  if (blob_columns && (file->ha_table_flags() & HA_NO_BLOBS))
2220
2148
  {
2221
2149
    my_message(ER_TABLE_CANT_HANDLE_BLOB, ER(ER_TABLE_CANT_HANDLE_BLOB),
2222
2150
               MYF(0));
2223
 
    DBUG_RETURN(TRUE);
 
2151
    return(true);
2224
2152
  }
2225
2153
 
2226
2154
  /* Create keys */
2239
2167
 
2240
2168
  while ((key=key_iterator++))
2241
2169
  {
2242
 
    DBUG_PRINT("info", ("key name: '%s'  type: %d", key->name.str ? key->name.str :
2243
 
                        "(none)" , key->type));
2244
2170
    if (key->type == Key::FOREIGN_KEY)
2245
2171
    {
2246
2172
      fk_key_count++;
2252
2178
                 (fk_key->name.str ? fk_key->name.str :
2253
2179
                                     "foreign key without name"),
2254
2180
                 ER(ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
2255
 
        DBUG_RETURN(TRUE);
 
2181
        return(true);
2256
2182
      }
2257
2183
      continue;
2258
2184
    }
2261
2187
    if (key->columns.elements > tmp)
2262
2188
    {
2263
2189
      my_error(ER_TOO_MANY_KEY_PARTS,MYF(0),tmp);
2264
 
      DBUG_RETURN(TRUE);
 
2190
      return(true);
2265
2191
    }
2266
2192
    if (check_identifier_name(&key->name, ER_TOO_LONG_IDENT))
2267
 
      DBUG_RETURN(TRUE);
 
2193
      return(true);
2268
2194
    key_iterator2.rewind ();
2269
2195
    if (key->type != Key::FOREIGN_KEY)
2270
2196
    {
2303
2229
        !my_strcasecmp(system_charset_info,key->name.str, primary_key_name))
2304
2230
    {
2305
2231
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str);
2306
 
      DBUG_RETURN(TRUE);
 
2232
      return(true);
2307
2233
    }
2308
2234
  }
2309
2235
  tmp=file->max_keys();
2310
2236
  if (*key_count > tmp)
2311
2237
  {
2312
2238
    my_error(ER_TOO_MANY_KEYS,MYF(0),tmp);
2313
 
    DBUG_RETURN(TRUE);
 
2239
    return(true);
2314
2240
  }
2315
2241
 
2316
2242
  (*key_info_buffer)= key_info= (KEY*) sql_calloc(sizeof(KEY) * (*key_count));
2317
2243
  key_part_info=(KEY_PART_INFO*) sql_calloc(sizeof(KEY_PART_INFO)*key_parts);
2318
2244
  if (!*key_info_buffer || ! key_part_info)
2319
 
    DBUG_RETURN(TRUE);                          // Out of memory
 
2245
    return(true);                               // Out of memory
2320
2246
 
2321
2247
  key_iterator.rewind();
2322
2248
  key_number=0;
2377
2303
      my_error(ER_WRONG_STRING_LENGTH, MYF(0),
2378
2304
               key->key_create_info.comment.str,"INDEX COMMENT",
2379
2305
               (uint) INDEX_COMMENT_MAXLEN);
2380
 
      DBUG_RETURN(-1);
 
2306
      return(-1);
2381
2307
    }
2382
2308
 
2383
2309
    key_info->comment.length= key->key_create_info.comment.length;
2403
2329
      if (!sql_field)
2404
2330
      {
2405
2331
        my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), column->field_name.str);
2406
 
        DBUG_RETURN(TRUE);
 
2332
        return(true);
2407
2333
      }
2408
2334
      while ((dup_column= cols2++) != column)
2409
2335
      {
2413
2339
          my_printf_error(ER_DUP_FIELDNAME,
2414
2340
                          ER(ER_DUP_FIELDNAME),MYF(0),
2415
2341
                          column->field_name.str);
2416
 
          DBUG_RETURN(TRUE);
 
2342
          return(true);
2417
2343
        }
2418
2344
      }
2419
2345
      cols2.rewind();
2425
2351
          if (!(file->ha_table_flags() & HA_CAN_INDEX_BLOBS))
2426
2352
          {
2427
2353
            my_error(ER_BLOB_USED_AS_KEY, MYF(0), column->field_name.str);
2428
 
            DBUG_RETURN(TRUE);
 
2354
            return(true);
2429
2355
          }
2430
2356
          if (!column->length)
2431
2357
          {
2432
2358
            my_error(ER_BLOB_KEY_WITHOUT_LENGTH, MYF(0), column->field_name.str);
2433
 
            DBUG_RETURN(TRUE);
 
2359
            return(true);
2434
2360
          }
2435
2361
        }
2436
2362
        if (!(sql_field->flags & NOT_NULL_FLAG))
2448
2374
            if (!(file->ha_table_flags() & HA_NULL_IN_KEY))
2449
2375
            {
2450
2376
              my_error(ER_NULL_COLUMN_IN_INDEX, MYF(0), column->field_name.str);
2451
 
              DBUG_RETURN(TRUE);
 
2377
              return(true);
2452
2378
            }
2453
2379
          }
2454
2380
        }
2476
2402
            {
2477
2403
              /* not a critical problem */
2478
2404
              char warn_buff[MYSQL_ERRMSG_SIZE];
2479
 
              my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
2480
 
                          length);
 
2405
              snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
 
2406
                       length);
2481
2407
              push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2482
2408
                           ER_TOO_LONG_KEY, warn_buff);
2483
2409
              /* Align key length to multibyte char boundary */
2486
2412
            else
2487
2413
            {
2488
2414
              my_error(ER_TOO_LONG_KEY,MYF(0),length);
2489
 
              DBUG_RETURN(TRUE);
 
2415
              return(true);
2490
2416
            }
2491
2417
          }
2492
2418
        }
2498
2424
                    column->length != length)))
2499
2425
        {
2500
2426
          my_message(ER_WRONG_SUB_KEY, ER(ER_WRONG_SUB_KEY), MYF(0));
2501
 
          DBUG_RETURN(TRUE);
 
2427
          return(true);
2502
2428
        }
2503
2429
        else if (!(file->ha_table_flags() & HA_NO_PREFIX_CHAR_KEYS))
2504
2430
          length=column->length;
2506
2432
      else if (length == 0)
2507
2433
      {
2508
2434
        my_error(ER_WRONG_KEY_COLUMN, MYF(0), column->field_name.str);
2509
 
          DBUG_RETURN(TRUE);
 
2435
          return(true);
2510
2436
      }
2511
2437
      if (length > file->max_key_part_length())
2512
2438
      {
2515
2441
        {
2516
2442
          /* not a critical problem */
2517
2443
          char warn_buff[MYSQL_ERRMSG_SIZE];
2518
 
          my_snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
2519
 
                      length);
 
2444
          snprintf(warn_buff, sizeof(warn_buff), ER(ER_TOO_LONG_KEY),
 
2445
                   length);
2520
2446
          push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
2521
2447
                       ER_TOO_LONG_KEY, warn_buff);
2522
2448
          /* Align key length to multibyte char boundary */
2525
2451
        else
2526
2452
        {
2527
2453
          my_error(ER_TOO_LONG_KEY,MYF(0),length);
2528
 
          DBUG_RETURN(TRUE);
 
2454
          return(true);
2529
2455
        }
2530
2456
      }
2531
2457
      key_part_info->length=(uint16) length;
2558
2484
          {
2559
2485
            my_message(ER_MULTIPLE_PRI_KEY, ER(ER_MULTIPLE_PRI_KEY),
2560
2486
                       MYF(0));
2561
 
            DBUG_RETURN(TRUE);
 
2487
            return(true);
2562
2488
          }
2563
2489
          key_name=primary_key_name;
2564
2490
          primary_key=1;
2569
2495
        if (check_if_keyname_exists(key_name, *key_info_buffer, key_info))
2570
2496
        {
2571
2497
          my_error(ER_DUP_KEYNAME, MYF(0), key_name);
2572
 
          DBUG_RETURN(TRUE);
 
2498
          return(true);
2573
2499
        }
2574
2500
        key_info->name=(char*) key_name;
2575
2501
      }
2577
2503
    if (!key_info->name || check_column_name(key_info->name))
2578
2504
    {
2579
2505
      my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key_info->name);
2580
 
      DBUG_RETURN(TRUE);
 
2506
      return(true);
2581
2507
    }
2582
2508
    if (!(key_info->flags & HA_NULL_PART_KEY))
2583
2509
      unique_key=1;
2585
2511
    if (key_length > max_key_length)
2586
2512
    {
2587
2513
      my_error(ER_TOO_LONG_KEY,MYF(0),max_key_length);
2588
 
      DBUG_RETURN(TRUE);
 
2514
      return(true);
2589
2515
    }
2590
2516
    key_info++;
2591
2517
  }
2593
2519
      (file->ha_table_flags() & HA_REQUIRE_PRIMARY_KEY))
2594
2520
  {
2595
2521
    my_message(ER_REQUIRES_PRIMARY_KEY, ER(ER_REQUIRES_PRIMARY_KEY), MYF(0));
2596
 
    DBUG_RETURN(TRUE);
 
2522
    return(true);
2597
2523
  }
2598
2524
  if (auto_increment > 0)
2599
2525
  {
2600
2526
    my_message(ER_WRONG_AUTO_KEY, ER(ER_WRONG_AUTO_KEY), MYF(0));
2601
 
    DBUG_RETURN(TRUE);
 
2527
    return(true);
2602
2528
  }
2603
2529
  /* Sort keys in optimized order */
2604
2530
  my_qsort((uchar*) *key_info_buffer, *key_count, sizeof(KEY),
2632
2558
      */
2633
2559
 
2634
2560
      my_error(ER_INVALID_DEFAULT, MYF(0), sql_field->field_name);
2635
 
      DBUG_RETURN(TRUE);
 
2561
      return(true);
2636
2562
    }
2637
2563
  }
2638
2564
 
2639
 
  DBUG_RETURN(FALSE);
 
2565
  return(false);
2640
2566
}
2641
2567
 
2642
2568
 
2685
2611
        In this case the error is given
2686
2612
*/
2687
2613
 
2688
 
static bool prepare_blob_field(THD *thd, Create_field *sql_field)
 
2614
static bool prepare_blob_field(THD *thd __attribute__((__unused__)),
 
2615
                               Create_field *sql_field)
2689
2616
{
2690
 
  DBUG_ENTER("prepare_blob_field");
2691
2617
 
2692
2618
  if (sql_field->length > MAX_FIELD_VARCHARLENGTH &&
2693
2619
      !(sql_field->flags & BLOB_FLAG))
2694
2620
  {
2695
2621
    my_error(ER_TOO_BIG_FIELDLENGTH, MYF(0), sql_field->field_name,
2696
2622
             MAX_FIELD_VARCHARLENGTH / sql_field->charset->mbmaxlen);
2697
 
    DBUG_RETURN(1);
 
2623
    return(1);
2698
2624
  }
2699
2625
    
2700
2626
  if ((sql_field->flags & BLOB_FLAG) && sql_field->length)
2707
2633
    }
2708
2634
    sql_field->length= 0;
2709
2635
  }
2710
 
  DBUG_RETURN(0);
 
2636
  return(0);
2711
2637
}
2712
2638
 
2713
2639
 
2750
2676
    set_if_smaller(sql_field->length, MAX_FIELD_WIDTH-1);
2751
2677
  }
2752
2678
 
2753
 
  if (sql_field->sql_type == MYSQL_TYPE_BIT)
2754
 
  {
2755
 
    sql_field->pack_flag= FIELDFLAG_NUMBER |
2756
 
                          FIELDFLAG_TREAT_BIT_AS_CHAR;
2757
 
  }
2758
2679
  sql_field->create_length_to_internal_length();
2759
 
  DBUG_ASSERT(sql_field->def == 0);
 
2680
  assert(sql_field->def == 0);
2760
2681
  /* Can't go wrong as sql_field->def is not defined */
2761
2682
  (void) prepare_blob_field(thd, sql_field);
2762
2683
}
2791
2712
    and must be zero for standard create of table.
2792
2713
 
2793
2714
  RETURN VALUES
2794
 
    FALSE OK
2795
 
    TRUE  error
 
2715
    false OK
 
2716
    true  error
2796
2717
*/
2797
2718
 
2798
2719
bool mysql_create_table_no_lock(THD *thd,
2808
2729
  uint          db_options, key_count;
2809
2730
  KEY           *key_info_buffer;
2810
2731
  handler       *file;
2811
 
  bool          error= TRUE;
2812
 
  DBUG_ENTER("mysql_create_table_no_lock");
2813
 
  DBUG_PRINT("enter", ("db: '%s'  table: '%s'  tmp: %d",
2814
 
                       db, table_name, internal_tmp_table));
2815
 
 
2816
 
 
 
2732
  bool          error= true;
2817
2733
  /* Check for duplicate fields and check type of table to create */
2818
2734
  if (!alter_info->create_list.elements)
2819
2735
  {
2820
2736
    my_message(ER_TABLE_MUST_HAVE_COLUMNS, ER(ER_TABLE_MUST_HAVE_COLUMNS),
2821
2737
               MYF(0));
2822
 
    DBUG_RETURN(TRUE);
 
2738
    return(true);
2823
2739
  }
2824
2740
  if (check_engine(thd, table_name, create_info))
2825
 
    DBUG_RETURN(TRUE);
 
2741
    return(true);
2826
2742
  db_options= create_info->table_options;
2827
2743
  if (create_info->row_type == ROW_TYPE_DYNAMIC)
2828
2744
    db_options|=HA_OPTION_PACK_RECORD;
2831
2747
                              create_info->db_type)))
2832
2748
  {
2833
2749
    my_error(ER_OUTOFMEMORY, MYF(0), sizeof(handler));
2834
 
    DBUG_RETURN(TRUE);
 
2750
    return(true);
2835
2751
  }
2836
2752
 
2837
2753
  set_table_default_charset(thd, create_info, (char*) db);
2856
2772
    if (strchr(alias, FN_DEVCHAR))
2857
2773
    {
2858
2774
      my_error(ER_WRONG_TABLE_NAME, MYF(0), alias);
2859
 
      DBUG_RETURN(TRUE);
 
2775
      return(true);
2860
2776
    }
2861
2777
#endif
2862
2778
    path_length= build_table_filename(path, sizeof(path), db, alias, reg_ext,
2919
2835
    bool create_if_not_exists =
2920
2836
      create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS;
2921
2837
    int retcode = ha_table_exists_in_engine(thd, db, table_name);
2922
 
    DBUG_PRINT("info", ("exists_in_engine: %u",retcode));
2923
2838
    switch (retcode)
2924
2839
    {
2925
2840
      case HA_ERR_NO_SUCH_TABLE:
2926
2841
        /* Normal case, no table exists. we can go and create it */
2927
2842
        break;
2928
2843
      case HA_ERR_TABLE_EXIST:
2929
 
        DBUG_PRINT("info", ("Table existed in handler"));
2930
2844
 
2931
2845
      if (create_if_not_exists)
2932
2846
        goto warn;
2934
2848
      goto unlock_and_end;
2935
2849
        break;
2936
2850
      default:
2937
 
        DBUG_PRINT("info", ("error: %u from storage engine", retcode));
2938
2851
        my_error(retcode, MYF(0),table_name);
2939
2852
        goto unlock_and_end;
2940
2853
    }
2982
2895
      (void) rm_temporary_table(create_info->db_type, path, false);
2983
2896
      goto unlock_and_end;
2984
2897
    }
2985
 
    thd->thread_specific_used= TRUE;
 
2898
    thd->thread_specific_used= true;
2986
2899
  }
2987
2900
 
2988
2901
  /*
2996
2909
      (!thd->current_stmt_binlog_row_based ||
2997
2910
       (thd->current_stmt_binlog_row_based &&
2998
2911
        !(create_info->options & HA_LEX_CREATE_TMP_TABLE))))
2999
 
    write_bin_log(thd, TRUE, thd->query, thd->query_length);
3000
 
  error= FALSE;
 
2912
    write_bin_log(thd, true, thd->query, thd->query_length);
 
2913
  error= false;
3001
2914
unlock_and_end:
3002
2915
  VOID(pthread_mutex_unlock(&LOCK_open));
3003
2916
 
3004
2917
err:
3005
2918
  thd_proc_info(thd, "After create");
3006
2919
  delete file;
3007
 
  DBUG_RETURN(error);
 
2920
  return(error);
3008
2921
 
3009
2922
warn:
3010
 
  error= FALSE;
 
2923
  error= false;
3011
2924
  push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
3012
2925
                      ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
3013
2926
                      alias);
3028
2941
{
3029
2942
  TABLE *name_lock= 0;
3030
2943
  bool result;
3031
 
  DBUG_ENTER("mysql_create_table");
3032
2944
 
3033
2945
  /* Wait for any database locks */
3034
2946
  pthread_mutex_lock(&LOCK_lock_db);
3042
2954
  if (thd->killed)
3043
2955
  {
3044
2956
    pthread_mutex_unlock(&LOCK_lock_db);
3045
 
    DBUG_RETURN(TRUE);
 
2957
    return(true);
3046
2958
  }
3047
2959
  creating_table++;
3048
2960
  pthread_mutex_unlock(&LOCK_lock_db);
3051
2963
  {
3052
2964
    if (lock_table_name_if_not_cached(thd, db, table_name, &name_lock))
3053
2965
    {
3054
 
      result= TRUE;
 
2966
      result= true;
3055
2967
      goto unlock;
3056
2968
    }
3057
2969
    if (!name_lock)
3062
2974
                            ER_TABLE_EXISTS_ERROR, ER(ER_TABLE_EXISTS_ERROR),
3063
2975
                            table_name);
3064
2976
        create_info->table_existed= 1;
3065
 
        result= FALSE;
 
2977
        result= false;
3066
2978
      }
3067
2979
      else
3068
2980
      {
3069
2981
        my_error(ER_TABLE_EXISTS_ERROR,MYF(0),table_name);
3070
 
        result= TRUE;
 
2982
        result= true;
3071
2983
      }
3072
2984
      goto unlock;
3073
2985
    }
3082
2994
  if (name_lock)
3083
2995
  {
3084
2996
    pthread_mutex_lock(&LOCK_open);
3085
 
    unlink_open_table(thd, name_lock, FALSE);
 
2997
    unlink_open_table(thd, name_lock, false);
3086
2998
    pthread_mutex_unlock(&LOCK_open);
3087
2999
  }
3088
3000
  pthread_mutex_lock(&LOCK_lock_db);
3089
3001
  if (!--creating_table && creating_database)
3090
3002
    pthread_cond_signal(&COND_refresh);
3091
3003
  pthread_mutex_unlock(&LOCK_lock_db);
3092
 
  DBUG_RETURN(result);
 
3004
  return(result);
3093
3005
}
3094
3006
 
3095
3007
 
3154
3066
                                but only the table in the storage engine.
3155
3067
 
3156
3068
  RETURN
3157
 
    FALSE   OK
3158
 
    TRUE    Error
 
3069
    false   OK
 
3070
    true    Error
3159
3071
*/
3160
3072
 
3161
3073
bool
3169
3081
  char tmp_name[NAME_LEN+1];
3170
3082
  handler *file;
3171
3083
  int error=0;
3172
 
  DBUG_ENTER("mysql_rename_table");
3173
 
  DBUG_PRINT("enter", ("old: '%s'.'%s'  new: '%s'.'%s'",
3174
 
                       old_db, old_name, new_db, new_name));
3175
3084
 
3176
3085
  file= (base == NULL ? 0 :
3177
3086
         get_new_handler((TABLE_SHARE*) 0, thd->mem_root, base));
3216
3125
    my_error(ER_NOT_SUPPORTED_YET, MYF(0), "ALTER TABLE");
3217
3126
  else if (error)
3218
3127
    my_error(ER_ERROR_ON_RENAME, MYF(0), from, to, error);
3219
 
  DBUG_RETURN(error != 0);
 
3128
  return(error != 0);
3220
3129
}
3221
3130
 
3222
3131
 
3242
3151
void wait_while_table_is_used(THD *thd, TABLE *table,
3243
3152
                              enum ha_extra_function function)
3244
3153
{
3245
 
  DBUG_ENTER("wait_while_table_is_used");
3246
 
  DBUG_PRINT("enter", ("table: '%s'  share: 0x%lx  db_stat: %u  version: %lu",
3247
 
                       table->s->table_name.str, (ulong) table->s,
3248
 
                       table->db_stat, table->s->version));
3249
3154
 
3250
3155
  safe_mutex_assert_owner(&LOCK_open);
3251
3156
 
3252
3157
  VOID(table->file->extra(function));
3253
3158
  /* Mark all tables that are in use as 'old' */
3254
 
  mysql_lock_abort(thd, table, TRUE);   /* end threads waiting on lock */
 
3159
  mysql_lock_abort(thd, table, true);   /* end threads waiting on lock */
3255
3160
 
3256
3161
  /* Wait until all there are no other threads that has this table open */
3257
3162
  remove_table_from_cache(thd, table->s->db.str,
3258
3163
                          table->s->table_name.str,
3259
3164
                          RTFC_WAIT_OTHER_THREAD_FLAG);
3260
 
  DBUG_VOID_RETURN;
 
3165
  return;
3261
3166
}
3262
3167
 
3263
3168
/*
3279
3184
 
3280
3185
void close_cached_table(THD *thd, TABLE *table)
3281
3186
{
3282
 
  DBUG_ENTER("close_cached_table");
3283
3187
 
3284
3188
  wait_while_table_is_used(thd, table, HA_EXTRA_FORCE_REOPEN);
3285
3189
  /* Close lock if this is not got with LOCK TABLES */
3289
3193
    thd->lock=0;                        // Start locked threads
3290
3194
  }
3291
3195
  /* Close all copies of 'table'.  This also frees all LOCK TABLES lock */
3292
 
  unlink_open_table(thd, table, TRUE);
 
3196
  unlink_open_table(thd, table, true);
3293
3197
 
3294
3198
  /* When lock on LOCK_open is freed other threads can continue */
3295
3199
  broadcast_refresh();
3296
 
  DBUG_VOID_RETURN;
 
3200
  return;
3297
3201
}
3298
3202
 
3299
3203
static int send_check_errmsg(THD *thd, TABLE_LIST* table,
3322
3226
  char from[FN_REFLEN],tmp[FN_REFLEN+32];
3323
3227
  const char **ext;
3324
3228
  struct stat stat_info;
3325
 
  DBUG_ENTER("prepare_for_repair");
3326
3229
 
3327
3230
  if (!(check_opt->sql_flags & TT_USEFRM))
3328
 
    DBUG_RETURN(0);
 
3231
    return(0);
3329
3232
 
3330
3233
  if (!(table= table_list->table))              /* if open_ltable failed */
3331
3234
  {
3338
3241
                                  &error))))
3339
3242
    {
3340
3243
      pthread_mutex_unlock(&LOCK_open);
3341
 
      DBUG_RETURN(0);                           // Can't open frm file
 
3244
      return(0);                                // Can't open frm file
3342
3245
    }
3343
3246
 
3344
3247
    if (open_table_from_share(thd, share, "", 0, 0, 0, &tmp_table, OTM_OPEN))
3345
3248
    {
3346
3249
      release_table_share(share, RELEASE_NORMAL);
3347
3250
      pthread_mutex_unlock(&LOCK_open);
3348
 
      DBUG_RETURN(0);                           // Out of memory
 
3251
      return(0);                           // Out of memory
3349
3252
    }
3350
3253
    table= &tmp_table;
3351
3254
    pthread_mutex_unlock(&LOCK_open);
3386
3289
  if (stat(from, &stat_info))
3387
3290
    goto end;                           // Can't use USE_FRM flag
3388
3291
 
3389
 
  my_snprintf(tmp, sizeof(tmp), "%s-%lx_%lx",
3390
 
              from, current_pid, thd->thread_id);
 
3292
  snprintf(tmp, sizeof(tmp), "%s-%lx_%lx",
 
3293
           from, current_pid, thd->thread_id);
3391
3294
 
3392
3295
  /* If we could open the table, close it */
3393
3296
  if (table_list->table)
3434
3337
    to finish the repair in the handler later on.
3435
3338
  */
3436
3339
  pthread_mutex_lock(&LOCK_open);
3437
 
  if (reopen_name_locked_table(thd, table_list, TRUE))
 
3340
  if (reopen_name_locked_table(thd, table_list, true))
3438
3341
  {
3439
3342
    unlock_table_name(thd, table_list);
3440
3343
    pthread_mutex_unlock(&LOCK_open);
3451
3354
    closefrm(table, 1);                         // Free allocated memory
3452
3355
    pthread_mutex_unlock(&LOCK_open);
3453
3356
  }
3454
 
  DBUG_RETURN(error);
 
3357
  return(error);
3455
3358
}
3456
3359
 
3457
3360
 
3458
3361
 
3459
3362
/*
3460
3363
  RETURN VALUES
3461
 
    FALSE Message sent to net (admin operation went ok)
3462
 
    TRUE  Message should be sent by caller 
 
3364
    false Message sent to net (admin operation went ok)
 
3365
    true  Message should be sent by caller 
3463
3366
          (admin operation or network communication failed)
3464
3367
*/
3465
3368
static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
3482
3385
  LEX *lex= thd->lex;
3483
3386
  int result_code= 0;
3484
3387
  CHARSET_INFO *cs= system_charset_info;
3485
 
  DBUG_ENTER("mysql_admin_table");
3486
3388
 
3487
3389
  if (end_active_trans(thd))
3488
 
    DBUG_RETURN(1);
 
3390
    return(1);
3489
3391
  field_list.push_back(item = new Item_empty_string("Table",
3490
3392
                                                    NAME_CHAR_LEN * 2,
3491
3393
                                                    cs));
3498
3400
  item->maybe_null = 1;
3499
3401
  if (protocol->send_fields(&field_list,
3500
3402
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
3501
 
    DBUG_RETURN(TRUE);
 
3403
    return(true);
3502
3404
 
3503
 
  mysql_ha_rm_tables(thd, tables, FALSE);
 
3405
  mysql_ha_rm_tables(thd, tables, false);
3504
3406
 
3505
3407
  for (table= tables; table; table= table->next_local)
3506
3408
  {
3508
3410
    char* db = table->db;
3509
3411
    bool fatal_error=0;
3510
3412
 
3511
 
    DBUG_PRINT("admin", ("table: '%s'.'%s'", table->db, table->table_name));
3512
 
    DBUG_PRINT("admin", ("extra_open_options: %u", extra_open_options));
3513
3413
    strxmov(table_name, db, ".", table->table_name, NullS);
3514
3414
    thd->open_options|= extra_open_options;
3515
3415
    table->lock_type= lock_type;
3539
3439
      table->next_local= save_next_local;
3540
3440
      thd->open_options&= ~extra_open_options;
3541
3441
    }
3542
 
    DBUG_PRINT("admin", ("table: 0x%lx", (long) table->table));
3543
3442
 
3544
3443
    if (prepare_func)
3545
3444
    {
3546
 
      DBUG_PRINT("admin", ("calling prepare_func"));
3547
3445
      switch ((*prepare_func)(thd, table, check_opt)) {
3548
3446
      case  1:           // error, message written to net
3549
3447
        ha_autocommit_or_rollback(thd, 1);
3550
3448
        end_trans(thd, ROLLBACK);
3551
3449
        close_thread_tables(thd);
3552
 
        DBUG_PRINT("admin", ("simple error, admin next table"));
3553
3450
        continue;
3554
3451
      case -1:           // error, message could be written to net
3555
3452
        /* purecov: begin inspected */
3556
 
        DBUG_PRINT("admin", ("severe error, stop"));
3557
3453
        goto err;
3558
3454
        /* purecov: end */
3559
3455
      default:           // should be 0 otherwise
3560
 
        DBUG_PRINT("admin", ("prepare_func succeeded"));
3561
3456
        ;
3562
3457
      }
3563
3458
    }
3572
3467
    */
3573
3468
    if (!table->table)
3574
3469
    {
3575
 
      DBUG_PRINT("admin", ("open table failed"));
3576
3470
      if (!thd->warn_list.elements)
3577
3471
        push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
3578
3472
                     ER_CHECK_NO_SUCH_TABLE, ER(ER_CHECK_NO_SUCH_TABLE));
3584
3478
      /* purecov: begin inspected */
3585
3479
      char buff[FN_REFLEN + MYSQL_ERRMSG_SIZE];
3586
3480
      uint length;
3587
 
      DBUG_PRINT("admin", ("sending error message"));
3588
3481
      protocol->prepare_for_resend();
3589
3482
      protocol->store(table_name, system_charset_info);
3590
3483
      protocol->store(operator_name, system_charset_info);
3591
3484
      protocol->store(STRING_WITH_LEN("error"), system_charset_info);
3592
 
      length= my_snprintf(buff, sizeof(buff), ER(ER_OPEN_AS_READONLY),
3593
 
                          table_name);
 
3485
      length= snprintf(buff, sizeof(buff), ER(ER_OPEN_AS_READONLY),
 
3486
                       table_name);
3594
3487
      protocol->store(buff, length, system_charset_info);
3595
3488
      ha_autocommit_or_rollback(thd, 0);
3596
3489
      end_trans(thd, COMMIT);
3597
3490
      close_thread_tables(thd);
3598
 
      lex->reset_query_tables_list(FALSE);
 
3491
      lex->reset_query_tables_list(false);
3599
3492
      table->table=0;                           // For query cache
3600
3493
      if (protocol->write())
3601
3494
        goto err;
3606
3499
    /* Close all instances of the table to allow repair to rename files */
3607
3500
    if (lock_type == TL_WRITE && table->table->s->version)
3608
3501
    {
3609
 
      DBUG_PRINT("admin", ("removing table from cache"));
3610
3502
      pthread_mutex_lock(&LOCK_open);
3611
3503
      const char *old_message=thd->enter_cond(&COND_refresh, &LOCK_open,
3612
3504
                                              "Waiting to get writelock");
3613
 
      mysql_lock_abort(thd,table->table, TRUE);
 
3505
      mysql_lock_abort(thd,table->table, true);
3614
3506
      remove_table_from_cache(thd, table->table->s->db.str,
3615
3507
                              table->table->s->table_name.str,
3616
3508
                              RTFC_WAIT_OTHER_THREAD_FLAG |
3625
3517
    if (table->table->s->crashed && operator_func == &handler::ha_check)
3626
3518
    {
3627
3519
      /* purecov: begin inspected */
3628
 
      DBUG_PRINT("admin", ("sending crashed warning"));
3629
3520
      protocol->prepare_for_resend();
3630
3521
      protocol->store(table_name, system_charset_info);
3631
3522
      protocol->store(operator_name, system_charset_info);
3644
3535
          (table->table->file->ha_check_for_upgrade(check_opt) ==
3645
3536
           HA_ADMIN_NEEDS_ALTER))
3646
3537
      {
3647
 
        DBUG_PRINT("admin", ("recreating table"));
3648
3538
        ha_autocommit_or_rollback(thd, 1);
3649
3539
        close_thread_tables(thd);
3650
3540
        tmp_disable_binlog(thd); // binlogging is done by caller if wanted
3662
3552
      }
3663
3553
    }
3664
3554
 
3665
 
    DBUG_PRINT("admin", ("calling operator_func '%s'", operator_name));
3666
3555
    result_code = (table->table->file->*operator_func)(thd, check_opt);
3667
 
    DBUG_PRINT("admin", ("operator_func returned: %d", result_code));
3668
3556
 
3669
3557
send_result:
3670
3558
 
3693
3581
 
3694
3582
send_result_message:
3695
3583
 
3696
 
    DBUG_PRINT("info", ("result_code: %d", result_code));
3697
3584
    switch (result_code) {
3698
3585
    case HA_ADMIN_NOT_IMPLEMENTED:
3699
3586
      {
3700
3587
        char buf[ERRMSGSIZE+20];
3701
 
        uint length=my_snprintf(buf, ERRMSGSIZE,
3702
 
                                ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
 
3588
        uint length=snprintf(buf, ERRMSGSIZE,
 
3589
                             ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
3703
3590
        protocol->store(STRING_WITH_LEN("note"), system_charset_info);
3704
3591
        protocol->store(buf, length, system_charset_info);
3705
3592
      }
3708
3595
    case HA_ADMIN_NOT_BASE_TABLE:
3709
3596
      {
3710
3597
        char buf[ERRMSGSIZE+20];
3711
 
        uint length= my_snprintf(buf, ERRMSGSIZE,
3712
 
                                 ER(ER_BAD_TABLE_ERROR), table_name);
 
3598
        uint length= snprintf(buf, ERRMSGSIZE,
 
3599
                              ER(ER_BAD_TABLE_ERROR), table_name);
3713
3600
        protocol->store(STRING_WITH_LEN("note"), system_charset_info);
3714
3601
        protocol->store(buf, length, system_charset_info);
3715
3602
      }
3730
3617
      protocol->store(STRING_WITH_LEN("status"), system_charset_info);
3731
3618
      protocol->store(STRING_WITH_LEN("Operation need committed state"),
3732
3619
                      system_charset_info);
3733
 
      open_for_modify= FALSE;
 
3620
      open_for_modify= false;
3734
3621
      break;
3735
3622
 
3736
3623
    case HA_ADMIN_ALREADY_DONE:
3784
3671
      }
3785
3672
      if (result_code) // either mysql_recreate_table or analyze failed
3786
3673
      {
3787
 
        DBUG_ASSERT(thd->is_error());
 
3674
        assert(thd->is_error());
3788
3675
        if (thd->is_error())
3789
3676
        {
3790
3677
          const char *err_msg= thd->main_da.message();
3826
3713
      uint length;
3827
3714
 
3828
3715
      protocol->store(STRING_WITH_LEN("error"), system_charset_info);
3829
 
      length=my_snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
 
3716
      length=snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
3830
3717
      protocol->store(buf, length, system_charset_info);
3831
3718
      fatal_error=1;
3832
3719
      break;
3835
3722
    default:                            // Probably HA_ADMIN_INTERNAL_ERROR
3836
3723
      {
3837
3724
        char buf[ERRMSGSIZE+20];
3838
 
        uint length=my_snprintf(buf, ERRMSGSIZE,
3839
 
                                "Unknown - internal error %d during operation",
3840
 
                                result_code);
 
3725
        uint length=snprintf(buf, ERRMSGSIZE,
 
3726
                             "Unknown - internal error %d during operation",
 
3727
                             result_code);
3841
3728
        protocol->store(STRING_WITH_LEN("error"), system_charset_info);
3842
3729
        protocol->store(buf, length, system_charset_info);
3843
3730
        fatal_error=1;
3870
3757
  }
3871
3758
 
3872
3759
  my_eof(thd);
3873
 
  DBUG_RETURN(FALSE);
 
3760
  return(false);
3874
3761
 
3875
3762
err:
3876
3763
  ha_autocommit_or_rollback(thd, 1);
3878
3765
  close_thread_tables(thd);                     // Shouldn't be needed
3879
3766
  if (table)
3880
3767
    table->table=0;
3881
 
  DBUG_RETURN(TRUE);
 
3768
  return(true);
3882
3769
}
3883
3770
 
3884
3771
 
3885
3772
bool mysql_repair_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
3886
3773
{
3887
 
  DBUG_ENTER("mysql_repair_table");
3888
 
  DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
 
3774
  return(mysql_admin_table(thd, tables, check_opt,
3889
3775
                                "repair", TL_WRITE, 1,
3890
3776
                                test(check_opt->sql_flags & TT_USEFRM),
3891
3777
                                HA_OPEN_FOR_REPAIR,
3896
3782
 
3897
3783
bool mysql_optimize_table(THD* thd, TABLE_LIST* tables, HA_CHECK_OPT* check_opt)
3898
3784
{
3899
 
  DBUG_ENTER("mysql_optimize_table");
3900
 
  DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
 
3785
  return(mysql_admin_table(thd, tables, check_opt,
3901
3786
                                "optimize", TL_WRITE, 1,0,0,0,
3902
3787
                                &handler::ha_optimize));
3903
3788
}
3912
3797
    tables      Table list (one table only)
3913
3798
 
3914
3799
  RETURN VALUES
3915
 
   FALSE ok
3916
 
   TRUE  error
 
3800
   false ok
 
3801
   true  error
3917
3802
*/
3918
3803
 
3919
3804
bool mysql_assign_to_keycache(THD* thd, TABLE_LIST* tables,
3921
3806
{
3922
3807
  HA_CHECK_OPT check_opt;
3923
3808
  KEY_CACHE *key_cache;
3924
 
  DBUG_ENTER("mysql_assign_to_keycache");
3925
3809
 
3926
3810
  check_opt.init();
3927
3811
  pthread_mutex_lock(&LOCK_global_system_variables);
3929
3813
  {
3930
3814
    pthread_mutex_unlock(&LOCK_global_system_variables);
3931
3815
    my_error(ER_UNKNOWN_KEY_CACHE, MYF(0), key_cache_name->str);
3932
 
    DBUG_RETURN(TRUE);
 
3816
    return(true);
3933
3817
  }
3934
3818
  pthread_mutex_unlock(&LOCK_global_system_variables);
3935
3819
  check_opt.key_cache= key_cache;
3936
 
  DBUG_RETURN(mysql_admin_table(thd, tables, &check_opt,
 
3820
  return(mysql_admin_table(thd, tables, &check_opt,
3937
3821
                                "assign_to_keycache", TL_READ_NO_INSERT, 0, 0,
3938
3822
                                0, 0, &handler::assign_to_keycache));
3939
3823
}
3964
3848
    0     ok
3965
3849
*/
3966
3850
 
3967
 
int reassign_keycache_tables(THD *thd, KEY_CACHE *src_cache,
3968
 
                             KEY_CACHE *dst_cache)
 
3851
int reassign_keycache_tables(THD *thd __attribute__((__unused__)),
 
3852
                             KEY_CACHE *src_cache,
 
3853
                             KEY_CACHE *dst_cache)
3969
3854
{
3970
 
  DBUG_ENTER("reassign_keycache_tables");
3971
 
 
3972
 
  DBUG_ASSERT(src_cache != dst_cache);
3973
 
  DBUG_ASSERT(src_cache->in_init);
 
3855
  assert(src_cache != dst_cache);
 
3856
  assert(src_cache->in_init);
3974
3857
  src_cache->param_buff_size= 0;                // Free key cache
3975
3858
  ha_resize_key_cache(src_cache);
3976
3859
  ha_change_key_cache(src_cache, dst_cache);
3977
 
  DBUG_RETURN(0);
3978
 
}
3979
 
 
3980
 
 
3981
 
/*
3982
 
  Preload specified indexes for a table into key cache
3983
 
 
3984
 
  SYNOPSIS
3985
 
    mysql_preload_keys()
3986
 
    thd         Thread object
3987
 
    tables      Table list (one table only)
3988
 
 
3989
 
  RETURN VALUES
3990
 
    FALSE ok
3991
 
    TRUE  error
3992
 
*/
3993
 
 
3994
 
bool mysql_preload_keys(THD* thd, TABLE_LIST* tables)
3995
 
{
3996
 
  DBUG_ENTER("mysql_preload_keys");
3997
 
  /*
3998
 
    We cannot allow concurrent inserts. The storage engine reads
3999
 
    directly from the index file, bypassing the cache. It could read
4000
 
    outdated information if parallel inserts into cache blocks happen.
4001
 
  */
4002
 
   DBUG_RETURN(mysql_admin_table(thd, tables, 0,
4003
 
                                "preload_keys", TL_READ_NO_INSERT, 0, 0, 0, 0,
4004
 
                                &handler::preload_keys));
4005
 
}
4006
 
 
4007
 
 
 
3860
  return(0);
 
3861
}
4008
3862
 
4009
3863
/**
4010
3864
  @brief          Create frm file based on I_S table
4018
3872
    @retval       0                        success
4019
3873
    @retval       1                        error
4020
3874
*/
4021
 
 
4022
 
 
4023
3875
bool mysql_create_like_schema_frm(THD* thd, TABLE_LIST* schema_table,
4024
3876
                                  char *dst_path, HA_CREATE_INFO *create_info)
4025
3877
{
4028
3880
  bool tmp_table= (create_info->options & HA_LEX_CREATE_TMP_TABLE);
4029
3881
  uint keys= schema_table->table->s->keys;
4030
3882
  uint db_options= 0;
4031
 
  DBUG_ENTER("mysql_create_like_schema_frm");
4032
3883
 
4033
3884
  bzero((char*) &local_create_info, sizeof(local_create_info));
4034
3885
  local_create_info.db_type= schema_table->table->s->db_type();
4038
3889
  schema_table->table->use_all_columns();
4039
3890
  if (mysql_prepare_alter_table(thd, schema_table->table,
4040
3891
                                &local_create_info, &alter_info))
4041
 
    DBUG_RETURN(1);
 
3892
    return(1);
4042
3893
  if (mysql_prepare_create_table(thd, &local_create_info, &alter_info,
4043
3894
                                 tmp_table, &db_options,
4044
3895
                                 schema_table->table->file,
4045
3896
                                 &schema_table->table->s->key_info, &keys, 0))
4046
 
    DBUG_RETURN(1);
 
3897
    return(1);
4047
3898
  local_create_info.max_rows= 0;
4048
3899
  if (mysql_create_frm(thd, dst_path, NullS, NullS,
4049
3900
                       &local_create_info, alter_info.create_list,
4050
3901
                       keys, schema_table->table->s->key_info,
4051
3902
                       schema_table->table->file))
4052
 
    DBUG_RETURN(1);
4053
 
  DBUG_RETURN(0);
 
3903
    return(1);
 
3904
  return(0);
4054
3905
}
4055
3906
 
4056
3907
 
4065
3916
    create_info Create info
4066
3917
 
4067
3918
  RETURN VALUES
4068
 
    FALSE OK
4069
 
    TRUE  error
 
3919
    false OK
 
3920
    true  error
4070
3921
*/
4071
3922
 
4072
3923
bool mysql_create_like_table(THD* thd, TABLE_LIST* table, TABLE_LIST* src_table,
4078
3929
  char *db= table->db;
4079
3930
  char *table_name= table->table_name;
4080
3931
  int  err;
4081
 
  bool res= TRUE;
 
3932
  bool res= true;
4082
3933
  uint not_used;
4083
 
  DBUG_ENTER("mysql_create_like_table");
4084
3934
 
4085
3935
 
4086
3936
  /* CREATE TABLE ... LIKE is not allowed for views. */
4096
3946
    operations which matter.
4097
3947
  */
4098
3948
  if (open_tables(thd, &src_table, &not_used, 0))
4099
 
    DBUG_RETURN(TRUE);
 
3949
    return(true);
4100
3950
 
4101
3951
  strxmov(src_path, src_table->table->s->path.str, reg_ext, NullS);
4102
3952
 
4228
4078
        */
4229
4079
        table->table= name_lock;
4230
4080
        VOID(pthread_mutex_lock(&LOCK_open));
4231
 
        if (reopen_name_locked_table(thd, table, FALSE))
 
4081
        if (reopen_name_locked_table(thd, table, false))
4232
4082
        {
4233
4083
          VOID(pthread_mutex_unlock(&LOCK_open));
4234
4084
          goto err;
4235
4085
        }
4236
4086
        VOID(pthread_mutex_unlock(&LOCK_open));
4237
4087
 
4238
 
        IF_DBUG(int result=) store_create_info(thd, table, &query,
 
4088
        int result= store_create_info(thd, table, &query,
4239
4089
                                               create_info);
4240
4090
 
4241
 
        DBUG_ASSERT(result == 0); // store_create_info() always return 0
4242
 
        write_bin_log(thd, TRUE, query.ptr(), query.length());
 
4091
        assert(result == 0); // store_create_info() always return 0
 
4092
        write_bin_log(thd, true, query.ptr(), query.length());
4243
4093
      }
4244
4094
      else                                      // Case 1
4245
 
        write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
4095
        write_bin_log(thd, true, thd->query, thd->query_length);
4246
4096
    }
4247
4097
    /*
4248
4098
      Case 3 and 4 does nothing under RBR
4249
4099
    */
4250
4100
  }
4251
4101
  else
4252
 
    write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
4102
    write_bin_log(thd, true, thd->query, thd->query_length);
4253
4103
 
4254
 
  res= FALSE;
 
4104
  res= false;
4255
4105
  goto err;
4256
4106
 
4257
4107
table_exists:
4258
4108
  if (create_info->options & HA_LEX_CREATE_IF_NOT_EXISTS)
4259
4109
  {
4260
4110
    char warn_buff[MYSQL_ERRMSG_SIZE];
4261
 
    my_snprintf(warn_buff, sizeof(warn_buff),
4262
 
                ER(ER_TABLE_EXISTS_ERROR), table_name);
 
4111
    snprintf(warn_buff, sizeof(warn_buff),
 
4112
             ER(ER_TABLE_EXISTS_ERROR), table_name);
4263
4113
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE,
4264
4114
                 ER_TABLE_EXISTS_ERROR,warn_buff);
4265
 
    res= FALSE;
 
4115
    res= false;
4266
4116
  }
4267
4117
  else
4268
4118
    my_error(ER_TABLE_EXISTS_ERROR, MYF(0), table_name);
4271
4121
  if (name_lock)
4272
4122
  {
4273
4123
    pthread_mutex_lock(&LOCK_open);
4274
 
    unlink_open_table(thd, name_lock, FALSE);
 
4124
    unlink_open_table(thd, name_lock, false);
4275
4125
    pthread_mutex_unlock(&LOCK_open);
4276
4126
  }
4277
 
  DBUG_RETURN(res);
 
4127
  return(res);
4278
4128
}
4279
4129
 
4280
4130
 
4282
4132
{
4283
4133
  thr_lock_type lock_type = TL_READ_NO_INSERT;
4284
4134
 
4285
 
  DBUG_ENTER("mysql_analyze_table");
4286
 
  DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
 
4135
  return(mysql_admin_table(thd, tables, check_opt,
4287
4136
                                "analyze", lock_type, 1, 0, 0, 0,
4288
4137
                                &handler::ha_analyze));
4289
4138
}
4293
4142
{
4294
4143
  thr_lock_type lock_type = TL_READ_NO_INSERT;
4295
4144
 
4296
 
  DBUG_ENTER("mysql_check_table");
4297
 
  DBUG_RETURN(mysql_admin_table(thd, tables, check_opt,
 
4145
  return(mysql_admin_table(thd, tables, check_opt,
4298
4146
                                "check", lock_type,
4299
4147
                                0, 0, HA_OPEN_FOR_REPAIR, 0,
4300
4148
                                &handler::ha_check));
4310
4158
  TABLE *table;
4311
4159
  my_bool discard;
4312
4160
  int error;
4313
 
  DBUG_ENTER("mysql_discard_or_import_tablespace");
4314
4161
 
4315
4162
  /*
4316
4163
    Note that DISCARD/IMPORT TABLESPACE always is the only operation in an
4325
4172
   We set this flag so that ha_innobase::open and ::external_lock() do
4326
4173
   not complain when we lock the table
4327
4174
 */
4328
 
  thd->tablespace_op= TRUE;
 
4175
  thd->tablespace_op= true;
4329
4176
  if (!(table=open_ltable(thd, table_list, TL_WRITE, 0)))
4330
4177
  {
4331
 
    thd->tablespace_op=FALSE;
4332
 
    DBUG_RETURN(-1);
 
4178
    thd->tablespace_op=false;
 
4179
    return(-1);
4333
4180
  }
4334
4181
 
4335
4182
  error= table->file->ha_discard_or_import_tablespace(discard);
4345
4192
    error=1;
4346
4193
  if (error)
4347
4194
    goto err;
4348
 
  write_bin_log(thd, FALSE, thd->query, thd->query_length);
 
4195
  write_bin_log(thd, false, thd->query, thd->query_length);
4349
4196
 
4350
4197
err:
4351
4198
  ha_autocommit_or_rollback(thd, error);
4352
 
  thd->tablespace_op=FALSE;
 
4199
  thd->tablespace_op=false;
4353
4200
  
4354
4201
  if (error == 0)
4355
4202
  {
4356
4203
    my_ok(thd);
4357
 
    DBUG_RETURN(0);
 
4204
    return(0);
4358
4205
  }
4359
4206
 
4360
4207
  table->file->print_error(error, MYF(0));
4361
4208
    
4362
 
  DBUG_RETURN(-1);
 
4209
  return(-1);
4363
4210
}
4364
4211
 
4365
4212
/**
4424
4271
   table->key_info or key_info_buffer respectively for the indexes
4425
4272
   that need to be dropped and/or (re-)created.
4426
4273
 
4427
 
   @retval TRUE  error
4428
 
   @retval FALSE success
 
4274
   @retval true  error
 
4275
   @retval false success
4429
4276
*/
4430
4277
 
4431
4278
static
4450
4297
    create_info->varchar will be reset in mysql_prepare_create_table.
4451
4298
  */
4452
4299
  bool varchar= create_info->varchar;
4453
 
  DBUG_ENTER("compare_tables");
4454
4300
 
4455
4301
  {
4456
4302
    /*
4480
4326
                                   &ha_alter_info->key_info_buffer,
4481
4327
                                   &ha_alter_info->key_count,
4482
4328
                                   /* select_field_count */ 0))
4483
 
      DBUG_RETURN(TRUE);
 
4329
      return(true);
4484
4330
    /* Allocate result buffers. */
4485
4331
    if (! (ha_alter_info->index_drop_buffer=
4486
4332
           (uint*) thd->alloc(sizeof(uint) * table->s->keys)) ||
4487
4333
        ! (ha_alter_info->index_add_buffer=
4488
4334
           (uint*) thd->alloc(sizeof(uint) *
4489
4335
                              tmp_alter_info.key_list.elements)))
4490
 
      DBUG_RETURN(TRUE);
 
4336
      return(true);
4491
4337
  }
4492
4338
  /*
4493
4339
    First we setup ha_alter_flags based on what was detected
4495
4341
  */
4496
4342
  setup_ha_alter_flags(alter_info, alter_flags);
4497
4343
 
4498
 
#ifndef DBUG_OFF
4499
 
  {
4500
 
    char dbug_string[HA_MAX_ALTER_FLAGS+1];
4501
 
    alter_flags->print(dbug_string);
4502
 
    DBUG_PRINT("info", ("alter_flags:  %s", (char *) dbug_string));
4503
 
  }
4504
 
#endif
4505
4344
 
4506
4345
  /*
4507
4346
    Some very basic checks. If number of fields changes, or the
4627
4466
  KEY *new_key_end=
4628
4467
       ha_alter_info->key_info_buffer + ha_alter_info->key_count;
4629
4468
 
4630
 
  DBUG_PRINT("info", ("index count old: %d  new: %d",
4631
 
                      table->s->keys, ha_alter_info->key_count));
4632
4469
  /*
4633
4470
    Step through all keys of the old table and search matching new keys.
4634
4471
  */
4666
4503
      else
4667
4504
        *alter_flags|= HA_DROP_INDEX;
4668
4505
      *table_changes= IS_EQUAL_NO;
4669
 
      DBUG_PRINT("info", ("index dropped: '%s'", table_key->name));
4670
4506
      continue;
4671
4507
    }
4672
4508
 
4739
4575
        field->flags|= FIELD_IN_ADD_INDEX;
4740
4576
    }
4741
4577
    *table_changes= IS_EQUAL_NO;
4742
 
    DBUG_PRINT("info", ("index changed: '%s'", table_key->name));
4743
4578
  }
4744
4579
  /*end of for (; table_key < table_key_end;) */
4745
4580
 
4782
4617
      else
4783
4618
        *alter_flags|= HA_ADD_INDEX;
4784
4619
      *table_changes= IS_EQUAL_NO;
4785
 
      DBUG_PRINT("info", ("index added: '%s'", new_key->name));
4786
4620
    }
4787
4621
  }
4788
 
#ifndef DBUG_OFF
4789
 
  {
4790
 
    char dbug_string[HA_MAX_ALTER_FLAGS+1];
4791
 
    alter_flags->print(dbug_string);
4792
 
    DBUG_PRINT("info", ("alter_flags:  %s", (char *) dbug_string));
4793
 
  }
4794
 
#endif
4795
4622
 
4796
 
  DBUG_RETURN(FALSE);
 
4623
  return(false);
4797
4624
}
4798
4625
 
4799
4626
 
4808
4635
      keys_onoff             ENABLE | DISABLE | LEAVE_AS_IS
4809
4636
 
4810
4637
  RETURN VALUES
4811
 
    FALSE  OK
4812
 
    TRUE   Error
 
4638
    false  OK
 
4639
    true   Error
4813
4640
*/
4814
4641
 
4815
4642
static
4817
4644
                             enum enum_enable_or_disable keys_onoff)
4818
4645
{
4819
4646
  int error= 0;
4820
 
  DBUG_ENTER("alter_table_manage_keys");
4821
 
  DBUG_PRINT("enter", ("table=%p were_disabled=%d on_off=%d",
4822
 
             table, indexes_were_disabled, keys_onoff));
4823
 
 
4824
4647
  switch (keys_onoff) {
4825
4648
  case ENABLE:
4826
4649
    error= table->file->ha_enable_indexes(HA_KEY_SWITCH_NONUNIQ_SAVE);
4842
4665
  } else if (error)
4843
4666
    table->file->print_error(error, MYF(0));
4844
4667
 
4845
 
  DBUG_RETURN(error);
 
4668
  return(error);
4846
4669
}
4847
4670
 
4848
4671
int create_temporary_table(THD *thd,
4856
4679
  int error;
4857
4680
  char index_file[FN_REFLEN], data_file[FN_REFLEN];
4858
4681
  handlerton *old_db_type, *new_db_type;
4859
 
  DBUG_ENTER("create_temporary_table");
4860
4682
  old_db_type= table->s->db_type();
4861
4683
  new_db_type= create_info->db_type;
4862
4684
  /*
4905
4727
  else
4906
4728
    create_info->data_file_name=create_info->index_file_name=0;
4907
4729
 
4908
 
  if (new_db_type == old_db_type)
4909
 
  {
4910
 
    /*
4911
 
       Table has not changed storage engine.
4912
 
       If STORAGE and TABLESPACE have not been changed than copy them
4913
 
       from the original table
4914
 
    */
4915
 
    if (!create_info->tablespace &&
4916
 
        table->s->tablespace &&
4917
 
        create_info->default_storage_media == HA_SM_DEFAULT)
4918
 
      create_info->tablespace= table->s->tablespace;
4919
 
    if (create_info->default_storage_media == HA_SM_DEFAULT)
4920
 
      create_info->default_storage_media= table->s->default_storage_media;
4921
 
   }
4922
 
 
4923
4730
  /*
4924
4731
    Create a table with a temporary name.
4925
4732
    With create_info->frm_only == 1 this creates a .frm file only.
4930
4737
                            create_info, alter_info, 1, 0);
4931
4738
  reenable_binlog(thd);
4932
4739
 
4933
 
  DBUG_RETURN(error);
 
4740
  return(error);
4934
4741
}
4935
4742
 
4936
4743
/*
4965
4772
  TABLE *altered_table;
4966
4773
  char tmp_name[80];
4967
4774
  char path[FN_REFLEN];
4968
 
  DBUG_ENTER("create_altered_table");
4969
4775
 
4970
 
  my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx",
4971
 
              tmp_file_prefix, current_pid, thd->thread_id);
 
4776
  snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx",
 
4777
           tmp_file_prefix, current_pid, thd->thread_id);
4972
4778
  /* Safety fix for InnoDB */
4973
4779
  if (lower_case_table_names)
4974
4780
    my_casedn_str(files_charset_info, tmp_name);
4978
4784
                                     &altered_create_info,
4979
4785
                                     alter_info, db_change)))
4980
4786
  {
4981
 
    DBUG_PRINT("info", ("Error %u while creating temporary table", error));
4982
 
    DBUG_RETURN(NULL);
 
4787
    return(NULL);
4983
4788
  };
4984
4789
 
4985
4790
  build_table_filename(path, sizeof(path), new_db, tmp_name, "",
4986
4791
                       FN_IS_TMP);
4987
4792
  altered_table= open_temporary_table(thd, path, new_db, tmp_name, 1,
4988
4793
                                      OTM_ALTER);
4989
 
  DBUG_RETURN(altered_table);
 
4794
  return(altered_table);
4990
4795
 
4991
 
  DBUG_RETURN(NULL);
 
4796
  return(NULL);
4992
4797
}
4993
4798
 
4994
4799
 
5029
4834
  bool online= (table->file->ha_table_flags() & HA_ONLINE_ALTER)?true:false;
5030
4835
  TABLE *t_table;
5031
4836
 
5032
 
  DBUG_ENTER(" mysql_fast_or_online_alter_table");
5033
4837
  if (online)
5034
4838
  {
5035
4839
   /*
5120
4924
      state of the TABLE object which we used for obtaining of handler
5121
4925
      object to make it suitable for reopening.
5122
4926
    */
5123
 
    DBUG_ASSERT(t_table == table);
 
4927
    assert(t_table == table);
5124
4928
    table->open_placeholder= 1;
5125
4929
    VOID(pthread_mutex_lock(&LOCK_open));
5126
4930
    close_handle_and_leave_table_as_lock(table);
5129
4933
 
5130
4934
 err:
5131
4935
  if (error)
5132
 
    DBUG_PRINT("info", ("Got error %u", error));
5133
 
  DBUG_RETURN(error);
 
4936
    return(error);
 
4937
  return 0;
5134
4938
}
5135
4939
 
5136
4940
 
5170
4974
    Sets create_info->varchar if the table has a VARCHAR column.
5171
4975
    Prepares alter_info->create_list and alter_info->key_list with
5172
4976
    columns and keys of the new table.
5173
 
  @retval TRUE   error, out of memory or a semantical error in ALTER
 
4977
  @retval true   error, out of memory or a semantical error in ALTER
5174
4978
                 TABLE instructions
5175
 
  @retval FALSE  success
 
4979
  @retval false  success
5176
4980
*/
5177
4981
 
5178
4982
static bool
5195
4999
                           & ~(HA_OPTION_PACK_RECORD));
5196
5000
  uint used_fields= create_info->used_fields;
5197
5001
  KEY *key_info=table->key_info;
5198
 
  bool rc= TRUE;
5199
 
 
5200
 
  DBUG_ENTER("mysql_prepare_alter_table");
5201
 
 
5202
 
  create_info->varchar= FALSE;
 
5002
  bool rc= true;
 
5003
 
 
5004
 
 
5005
  create_info->varchar= false;
5203
5006
  /* Let new create options override the old ones */
5204
5007
  if (!(used_fields & HA_CREATE_USED_MIN_ROWS))
5205
5008
    create_info->min_rows= table->s->min_rows;
5230
5033
  for (f_ptr=table->field ; (field= *f_ptr) ; f_ptr++)
5231
5034
    {
5232
5035
    if (field->type() == MYSQL_TYPE_STRING)
5233
 
      create_info->varchar= TRUE;
 
5036
      create_info->varchar= true;
5234
5037
    /* Check if field should be dropped */
5235
5038
    Alter_drop *drop;
5236
5039
    drop_it.rewind();
5316
5119
      If the '0000-00-00' value isn't allowed then raise the error_if_not_empty
5317
5120
      flag to allow ALTER TABLE only if the table to be altered is empty.
5318
5121
      */
5319
 
    if ((def->sql_type == MYSQL_TYPE_DATE ||
5320
 
         def->sql_type == MYSQL_TYPE_NEWDATE ||
 
5122
    if ((def->sql_type == MYSQL_TYPE_NEWDATE ||
5321
5123
         def->sql_type == MYSQL_TYPE_DATETIME) &&
5322
5124
         !alter_info->datetime_field &&
5323
5125
         !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) &&
5324
5126
         thd->variables.sql_mode & MODE_NO_ZERO_DATE)
5325
5127
    {
5326
5128
        alter_info->datetime_field= def;
5327
 
        alter_info->error_if_not_empty= TRUE;
 
5129
        alter_info->error_if_not_empty= true;
5328
5130
    }
5329
5131
    if (!def->after)
5330
5132
      new_create_list.push_back(def);
5530
5332
  if (table->s->tmp_table)
5531
5333
    create_info->options|=HA_LEX_CREATE_TMP_TABLE;
5532
5334
 
5533
 
  rc= FALSE;
 
5335
  rc= false;
5534
5336
  alter_info->create_list.swap(new_create_list);
5535
5337
  alter_info->key_list.swap(new_key_list);
5536
5338
err:
5537
 
  DBUG_RETURN(rc);
 
5339
  return(rc);
5538
5340
}
5539
5341
 
5540
5342
 
5576
5378
    tables.
5577
5379
 
5578
5380
  RETURN VALUES
5579
 
    FALSE  OK
5580
 
    TRUE   Error
 
5381
    false  OK
 
5382
    true   Error
5581
5383
*/
5582
5384
 
5583
5385
bool mysql_alter_table(THD *thd,char *new_db, char *new_name,
5595
5397
  handlerton *old_db_type, *new_db_type, *save_old_db_type;
5596
5398
  legacy_db_type table_type;
5597
5399
  frm_type_enum frm_type;
5598
 
  DBUG_ENTER("mysql_alter_table");
5599
5400
 
5600
5401
  if (table_list && table_list->schema_table)
5601
5402
  {
5602
5403
    my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), "", "", INFORMATION_SCHEMA_NAME.str);
5603
 
    DBUG_RETURN(TRUE);
 
5404
    return(true);
5604
5405
  }
5605
5406
 
5606
5407
  /*
5616
5417
    new_db= db;
5617
5418
  build_table_filename(path, sizeof(path), db, table_name, "", 0);
5618
5419
 
5619
 
  mysql_ha_rm_tables(thd, table_list, FALSE);
 
5420
  mysql_ha_rm_tables(thd, table_list, false);
5620
5421
 
5621
5422
  /* DISCARD/IMPORT TABLESPACE is always alone in an ALTER TABLE */
5622
5423
  if (alter_info->tablespace_op != NO_TABLESPACE_OP)
5623
5424
    /* Conditionally writes to binlog. */
5624
 
    DBUG_RETURN(mysql_discard_or_import_tablespace(thd,table_list,
5625
 
                                                   alter_info->tablespace_op));
 
5425
    return(mysql_discard_or_import_tablespace(thd,table_list,
 
5426
                                              alter_info->tablespace_op));
5626
5427
  strxnmov(new_name_buff, sizeof (new_name_buff) - 1, mysql_data_home, "/", db, 
5627
5428
           "/", table_name, reg_ext, NullS);
5628
5429
  (void) unpack_filename(new_name_buff, new_name_buff);
5642
5443
  frm_type= mysql_frm_type(thd, new_name_buff, &table_type);
5643
5444
 
5644
5445
  if (!(table= open_n_lock_single_table(thd, table_list, TL_WRITE_ALLOW_READ)))
5645
 
    DBUG_RETURN(TRUE);
 
5446
    return(true);
5646
5447
  table->use_all_columns();
5647
5448
 
5648
5449
  /*
5656
5457
      (table->s->tmp_table == NO_TMP_TABLE))
5657
5458
  {
5658
5459
    my_error(ER_LOCK_OR_ACTIVE_TRANSACTION, MYF(0));
5659
 
    DBUG_RETURN(TRUE);
 
5460
    return(true);
5660
5461
  }
5661
5462
 
5662
5463
  /* Check that we are not trying to rename to an existing table */
5663
5464
  if (new_name)
5664
5465
  {
5665
 
    DBUG_PRINT("info", ("new_db.new_name: '%s'.'%s'", new_db, new_name));
5666
5466
    strmov(new_name_buff,new_name);
5667
5467
    strmov(new_alias= new_alias_buff, new_name);
5668
5468
    if (lower_case_table_names)
5690
5490
        if (find_temporary_table(thd,new_db,new_name_buff))
5691
5491
        {
5692
5492
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_name_buff);
5693
 
          DBUG_RETURN(TRUE);
 
5493
          return(true);
5694
5494
        }
5695
5495
      }
5696
5496
      else
5697
5497
      {
5698
5498
        if (lock_table_name_if_not_cached(thd, new_db, new_name, &name_lock))
5699
 
          DBUG_RETURN(TRUE);
 
5499
          return(true);
5700
5500
        if (!name_lock)
5701
5501
        {
5702
5502
          my_error(ER_TABLE_EXISTS_ERROR, MYF(0), new_alias);
5703
 
          DBUG_RETURN(TRUE);
 
5503
          return(true);
5704
5504
        }
5705
5505
 
5706
5506
        build_table_filename(new_name_buff, sizeof(new_name_buff),
5740
5540
  if (create_info->row_type == ROW_TYPE_NOT_USED)
5741
5541
    create_info->row_type= table->s->row_type;
5742
5542
 
5743
 
  DBUG_PRINT("info", ("old type: %s  new type: %s",
5744
 
             ha_resolve_storage_engine_name(old_db_type),
5745
 
             ha_resolve_storage_engine_name(new_db_type)));
5746
5543
  if (ha_check_storage_engine_flag(old_db_type, HTON_ALTER_NOT_SUPPORTED) ||
5747
5544
      ha_check_storage_engine_flag(new_db_type, HTON_ALTER_NOT_SUPPORTED))
5748
5545
  {
5749
 
    DBUG_PRINT("info", ("doesn't support alter"));
5750
5546
    my_error(ER_ILLEGAL_HA, MYF(0), table_name);
5751
5547
    goto err;
5752
5548
  }
5783
5579
      /* COND_refresh will be signaled in close_thread_tables() */
5784
5580
      break;
5785
5581
    default:
5786
 
      DBUG_ASSERT(FALSE);
 
5582
      assert(false);
5787
5583
      error= 0;
5788
5584
      break;
5789
5585
    }
5850
5646
 
5851
5647
    if (!error)
5852
5648
    {
5853
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
5649
      write_bin_log(thd, true, thd->query, thd->query_length);
5854
5650
      my_ok(thd);
5855
5651
  }
5856
5652
    else if (error > 0)
5859
5655
      error= -1;
5860
5656
    }
5861
5657
    if (name_lock)
5862
 
      unlink_open_table(thd, name_lock, FALSE);
 
5658
      unlink_open_table(thd, name_lock, false);
5863
5659
    VOID(pthread_mutex_unlock(&LOCK_open));
5864
5660
    table_list->table= NULL;                    // For query cache
5865
 
    DBUG_RETURN(error);
 
5661
    return(error);
5866
5662
  }
5867
5663
 
5868
5664
  /* We have to do full alter table. */
5904
5700
    HA_ALTER_INFO ha_alter_info;
5905
5701
    HA_ALTER_FLAGS ha_alter_flags;
5906
5702
    uint table_changes= IS_EQUAL_YES;
5907
 
    bool need_copy_table= TRUE;
 
5703
    bool need_copy_table= true;
5908
5704
    /* Check how much the tables differ. */
5909
5705
    if (compare_tables(thd, table, alter_info,
5910
5706
                       create_info, order_num,
5912
5708
                       &ha_alter_info,
5913
5709
                       &table_changes))
5914
5710
    {
5915
 
      DBUG_RETURN(TRUE);
 
5711
      return(true);
5916
5712
    }
5917
5713
 
5918
5714
    /*
5920
5716
      on-line.
5921
5717
    */
5922
5718
 
5923
 
#ifndef DBUG_OFF
5924
 
    {
5925
 
      char dbug_string[HA_MAX_ALTER_FLAGS+1];
5926
 
      ha_alter_flags.print(dbug_string);
5927
 
      DBUG_PRINT("info", ("need_copy_table: %u, table_changes: %u, Real alter_flags:  %s",
5928
 
                          need_copy_table, table_changes,
5929
 
                          (char *) dbug_string));
5930
 
    }
5931
 
#endif
5932
5719
 
5933
5720
    /*
5934
5721
      If table is not renamed, changed database and
5967
5754
          call check_if_supported_alter has provision for this
5968
5755
          already now.
5969
5756
        */
5970
 
        need_copy_table= FALSE;
 
5757
        need_copy_table= false;
5971
5758
        break;
5972
5759
      case HA_ALTER_NOT_SUPPORTED:
5973
5760
        if (alter_info->build_method == HA_BUILD_ONLINE)
5976
5763
          close_temporary_table(thd, altered_table, 1, 1);
5977
5764
          goto err;
5978
5765
        }
5979
 
        need_copy_table= TRUE;
 
5766
        need_copy_table= true;
5980
5767
        break;
5981
5768
      case HA_ALTER_ERROR:
5982
5769
      default:
5983
5770
        close_temporary_table(thd, altered_table, 1, 1);
5984
5771
        goto err;
5985
5772
      }
5986
 
#ifndef DBUG_OFF
5987
 
      {
5988
 
        char dbug_string[HA_MAX_ALTER_FLAGS+1];
5989
 
        ha_alter_flags.print(dbug_string);
5990
 
        DBUG_PRINT("info", ("need_copy_table: %u, table_changes: %u, Real alter_flags:  %s",
5991
 
                            need_copy_table, table_changes,
5992
 
                            (char *) dbug_string));
5993
 
      }
5994
 
#endif
5995
5773
 
5996
5774
    }
5997
5775
    /* TODO need to check if changes can be handled as fast ALTER TABLE */
5998
5776
    if (!altered_table)
5999
 
      need_copy_table= TRUE;
 
5777
      need_copy_table= true;
6000
5778
 
6001
5779
    if (!need_copy_table)
6002
5780
    {
6034
5812
      close_temporary_table(thd, altered_table, 1, 1);
6035
5813
  }
6036
5814
 
6037
 
  my_snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx", tmp_file_prefix,
6038
 
              current_pid, thd->thread_id);
 
5815
  snprintf(tmp_name, sizeof(tmp_name), "%s-%lx_%lx", tmp_file_prefix,
 
5816
           current_pid, thd->thread_id);
6039
5817
  /* Safety fix for innodb */
6040
5818
  if (lower_case_table_names)
6041
5819
    my_casedn_str(files_charset_info, tmp_name);
6123
5901
      goto err1;
6124
5902
    /* We don't replicate alter table statement on temporary tables */
6125
5903
    if (!thd->current_stmt_binlog_row_based)
6126
 
      write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
5904
      write_bin_log(thd, true, thd->query, thd->query_length);
6127
5905
    goto end_temporary;
6128
5906
  }
6129
5907
 
6161
5939
  */
6162
5940
 
6163
5941
  thd_proc_info(thd, "rename result table");
6164
 
  my_snprintf(old_name, sizeof(old_name), "%s2-%lx-%lx", tmp_file_prefix,
6165
 
              current_pid, thd->thread_id);
 
5942
  snprintf(old_name, sizeof(old_name), "%s2-%lx-%lx", tmp_file_prefix,
 
5943
           current_pid, thd->thread_id);
6166
5944
  if (lower_case_table_names)
6167
5945
    my_casedn_str(files_charset_info, old_name);
6168
5946
 
6223
6001
 
6224
6002
  thd_proc_info(thd, "end");
6225
6003
 
6226
 
  DBUG_EXECUTE_IF("sleep_alter_before_main_binlog", my_sleep(6000000););
6227
 
 
6228
6004
  ha_binlog_log_query(thd, create_info->db_type, LOGCOM_ALTER_TABLE,
6229
6005
                      thd->query, thd->query_length,
6230
6006
                      db, table_name);
6231
6007
 
6232
 
  DBUG_ASSERT(!(mysql_bin_log.is_open() &&
 
6008
  assert(!(mysql_bin_log.is_open() &&
6233
6009
                thd->current_stmt_binlog_row_based &&
6234
6010
                (create_info->options & HA_LEX_CREATE_TMP_TABLE)));
6235
 
  write_bin_log(thd, TRUE, thd->query, thd->query_length);
 
6011
  write_bin_log(thd, true, thd->query, thd->query_length);
6236
6012
 
6237
6013
  if (ha_check_storage_engine_flag(old_db_type, HTON_FLUSH_AFTER_RENAME))
6238
6014
  {
6244
6020
    char path[FN_REFLEN];
6245
6021
    TABLE *t_table;
6246
6022
    build_table_filename(path, sizeof(path), new_db, table_name, "", 0);
6247
 
    t_table= open_temporary_table(thd, path, new_db, tmp_name, FALSE, OTM_OPEN);
 
6023
    t_table= open_temporary_table(thd, path, new_db, tmp_name, false, OTM_OPEN);
6248
6024
    if (t_table)
6249
6025
    {
6250
6026
      intern_close_table(t_table);
6266
6042
      LOCK TABLES we can rely on close_thread_tables() doing this job.
6267
6043
    */
6268
6044
    pthread_mutex_lock(&LOCK_open);
6269
 
    unlink_open_table(thd, table, FALSE);
6270
 
    unlink_open_table(thd, name_lock, FALSE);
 
6045
    unlink_open_table(thd, table, false);
 
6046
    unlink_open_table(thd, name_lock, false);
6271
6047
    pthread_mutex_unlock(&LOCK_open);
6272
6048
  }
6273
6049
 
6274
6050
end_temporary:
6275
 
  my_snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
6276
 
              (ulong) (copied + deleted), (ulong) deleted,
6277
 
              (ulong) thd->cuted_fields);
 
6051
  snprintf(tmp_name, sizeof(tmp_name), ER(ER_INSERT_INFO),
 
6052
           (ulong) (copied + deleted), (ulong) deleted,
 
6053
           (ulong) thd->cuted_fields);
6278
6054
  my_ok(thd, copied + deleted, 0L, tmp_name);
6279
6055
  thd->some_tables_deleted=0;
6280
 
  DBUG_RETURN(FALSE);
 
6056
  return(false);
6281
6057
 
6282
6058
err1:
6283
6059
  if (new_table)
6301
6077
    enum enum_mysql_timestamp_type t_type= MYSQL_TIMESTAMP_DATE;
6302
6078
    switch (alter_info->datetime_field->sql_type)
6303
6079
    {
6304
 
      case MYSQL_TYPE_DATE:
6305
6080
      case MYSQL_TYPE_NEWDATE:
6306
6081
        f_val= "0000-00-00";
6307
6082
        t_type= MYSQL_TIMESTAMP_DATE;
6312
6087
        break;
6313
6088
      default:
6314
6089
        /* Shouldn't get here. */
6315
 
        DBUG_ASSERT(0);
 
6090
        assert(0);
6316
6091
    }
6317
6092
    bool save_abort_on_warning= thd->abort_on_warning;
6318
 
    thd->abort_on_warning= TRUE;
 
6093
    thd->abort_on_warning= true;
6319
6094
    make_truncated_value_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR,
6320
6095
                                 f_val, strlength(f_val), t_type,
6321
6096
                                 alter_info->datetime_field->field_name);
6324
6099
  if (name_lock)
6325
6100
  {
6326
6101
    pthread_mutex_lock(&LOCK_open);
6327
 
    unlink_open_table(thd, name_lock, FALSE);
 
6102
    unlink_open_table(thd, name_lock, false);
6328
6103
    pthread_mutex_unlock(&LOCK_open);
6329
6104
  }
6330
 
  DBUG_RETURN(TRUE);
 
6105
  return(true);
6331
6106
 
6332
6107
err_with_placeholders:
6333
6108
  /*
6335
6110
    being altered. To be safe under LOCK TABLES we should remove placeholders
6336
6111
    from list of open tables list and table cache.
6337
6112
  */
6338
 
  unlink_open_table(thd, table, FALSE);
 
6113
  unlink_open_table(thd, table, false);
6339
6114
  if (name_lock)
6340
 
    unlink_open_table(thd, name_lock, FALSE);
 
6115
    unlink_open_table(thd, name_lock, false);
6341
6116
  VOID(pthread_mutex_unlock(&LOCK_open));
6342
 
  DBUG_RETURN(TRUE);
 
6117
  return(true);
6343
6118
}
6344
6119
/* mysql_alter_table */
6345
6120
 
6367
6142
  bool auto_increment_field_copied= 0;
6368
6143
  ulong save_sql_mode;
6369
6144
  ulonglong prev_insert_id;
6370
 
  DBUG_ENTER("copy_data_between_tables");
6371
6145
 
6372
6146
  /*
6373
6147
    Turn off recovery logging since rollback of an alter table is to
6375
6149
    
6376
6150
    This needs to be done before external_lock
6377
6151
  */
6378
 
  error= ha_enable_transaction(thd, FALSE);
 
6152
  error= ha_enable_transaction(thd, false);
6379
6153
  if (error)
6380
 
    DBUG_RETURN(-1);
 
6154
    return(-1);
6381
6155
  
6382
6156
  if (!(copy= new Copy_field[to->s->fields]))
6383
 
    DBUG_RETURN(-1);                            /* purecov: inspected */
 
6157
    return(-1);                         /* purecov: inspected */
6384
6158
 
6385
6159
  if (to->file->ha_external_lock(thd, F_WRLCK))
6386
 
    DBUG_RETURN(-1);
 
6160
    return(-1);
6387
6161
 
6388
6162
  /* We need external lock before we can disable/enable keys */
6389
6163
  alter_table_manage_keys(to, from->file->indexes_are_disabled(), keys_onoff);
6406
6180
    {
6407
6181
      if (*ptr == to->next_number_field)
6408
6182
      {
6409
 
        auto_increment_field_copied= TRUE;
 
6183
        auto_increment_field_copied= true;
6410
6184
        /*
6411
6185
          If we are going to copy contents of one auto_increment column to
6412
6186
          another auto_increment column it is sensible to preserve zeroes.
6428
6202
    if (to->s->primary_key != MAX_KEY && to->file->primary_key_is_clustered())
6429
6203
    {
6430
6204
      char warn_buff[MYSQL_ERRMSG_SIZE];
6431
 
      my_snprintf(warn_buff, sizeof(warn_buff), 
6432
 
                  "ORDER BY ignored as there is a user-defined clustered index"
6433
 
                  " in the table '%-.192s'", from->s->table_name.str);
 
6205
      snprintf(warn_buff, sizeof(warn_buff), 
 
6206
               "ORDER BY ignored as there is a user-defined clustered index"
 
6207
               " in the table '%-.192s'", from->s->table_name.str);
6434
6208
      push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
6435
6209
                   warn_buff);
6436
6210
    }
6481
6255
    if (to->next_number_field)
6482
6256
    {
6483
6257
      if (auto_increment_field_copied)
6484
 
        to->auto_increment_field_not_null= TRUE;
 
6258
        to->auto_increment_field_not_null= true;
6485
6259
      else
6486
6260
        to->next_number_field->reset();
6487
6261
    }
6492
6266
    }
6493
6267
    prev_insert_id= to->file->next_insert_id;
6494
6268
    error=to->file->ha_write_row(to->record[0]);
6495
 
    to->auto_increment_field_not_null= FALSE;
 
6269
    to->auto_increment_field_not_null= false;
6496
6270
    if (error)
6497
6271
    {
6498
6272
      if (!ignore ||
6533
6307
  }
6534
6308
  to->file->extra(HA_EXTRA_NO_IGNORE_DUP_KEY);
6535
6309
 
6536
 
  if (ha_enable_transaction(thd, TRUE))
 
6310
  if (ha_enable_transaction(thd, true))
6537
6311
  {
6538
6312
    error= 1;
6539
6313
    goto err;
6557
6331
  to->file->ha_release_auto_increment();
6558
6332
  if (to->file->ha_external_lock(thd,F_UNLCK))
6559
6333
    error=1;
6560
 
  DBUG_RETURN(error > 0 ? -1 : 0);
 
6334
  return(error > 0 ? -1 : 0);
6561
6335
}
6562
6336
 
6563
6337
 
6577
6351
  HA_CREATE_INFO create_info;
6578
6352
  Alter_info alter_info;
6579
6353
 
6580
 
  DBUG_ENTER("mysql_recreate_table");
6581
 
  DBUG_ASSERT(!table_list->next_global);
 
6354
  assert(!table_list->next_global);
6582
6355
  /*
6583
6356
    table_list->table has been closed and freed. Do not reference
6584
6357
    uninitialized data. open_tables() could fail.
6590
6363
  create_info.default_table_charset=default_charset_info;
6591
6364
  /* Force alter table to recreate table */
6592
6365
  alter_info.flags= (ALTER_CHANGE_COLUMN | ALTER_RECREATE);
6593
 
  DBUG_RETURN(mysql_alter_table(thd, NullS, NullS, &create_info,
 
6366
  return(mysql_alter_table(thd, NullS, NullS, &create_info,
6594
6367
                                table_list, &alter_info, 0,
6595
6368
                                (ORDER *) 0, 0));
6596
6369
}
6603
6376
  List<Item> field_list;
6604
6377
  Item *item;
6605
6378
  Protocol *protocol= thd->protocol;
6606
 
  DBUG_ENTER("mysql_checksum_table");
6607
6379
 
6608
6380
  field_list.push_back(item = new Item_empty_string("Table", NAME_LEN*2));
6609
6381
  item->maybe_null= 1;
6612
6384
  item->maybe_null= 1;
6613
6385
  if (protocol->send_fields(&field_list,
6614
6386
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
6615
 
    DBUG_RETURN(TRUE);
 
6387
    return(true);
6616
6388
 
6617
6389
  /* Open one table after the other to keep lock time as short as possible. */
6618
6390
  for (table= tables; table; table= table->next_local)
6704
6476
  }
6705
6477
 
6706
6478
  my_eof(thd);
6707
 
  DBUG_RETURN(FALSE);
 
6479
  return(false);
6708
6480
 
6709
6481
 err:
6710
6482
  close_thread_tables(thd);                     // Shouldn't be needed
6711
6483
  if (table)
6712
6484
    table->table=0;
6713
 
  DBUG_RETURN(TRUE);
 
6485
  return(true);
6714
6486
}
6715
6487
 
6716
6488
static bool check_engine(THD *thd, const char *table_name,
6721
6493
  bool no_substitution= 1;
6722
6494
  if (!(*new_engine= ha_checktype(thd, ha_legacy_type(req_engine),
6723
6495
                                  no_substitution, 1)))
6724
 
    return TRUE;
 
6496
    return true;
6725
6497
 
6726
6498
  if (req_engine && req_engine != *new_engine)
6727
6499
  {
6739
6511
      my_error(ER_ILLEGAL_HA_CREATE_OPTION, MYF(0),
6740
6512
               ha_resolve_storage_engine_name(*new_engine), "TEMPORARY");
6741
6513
      *new_engine= 0;
6742
 
      return TRUE;
 
6514
      return true;
6743
6515
    }
6744
6516
    *new_engine= myisam_hton;
6745
6517
  }
6746
 
  return FALSE;
 
6518
  return false;
6747
6519
}