~ubuntu-branches/ubuntu/gutsy/mysql-dfsg-5.0/gutsy

« back to all changes in this revision

Viewing changes to sql/ha_myisam.cc

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2007-04-03 09:43:01 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20070403094301-fnjhfr59hu72pvtg
Tags: 5.0.38-0ubuntu1
* Package the Enterprise version again (.37 was a community version), since
  Debian and we have always done so. This brings in a few more bug fixes and
  makes functional derivations less likely.
* debian/README.Maintainer: Add pointer to upstream download URL, since it
  is very hard to find the Enterprise versions.
* Disable 33_scripts__mysql_create_system_tables__no_test.dpatch, since that
  script was removed upstream.
* debian/patches/41_scripts__mysql_install_db.sh__no_test.dpatch: Adapted to
  changed formatting in new upstream version.
* Remove debian/patches/86_PATH_MAX.dpatch, fixed upstream.
* Add debian/patches/90_org_tables_definition.dpatch: Fix local variable
  declaration in libmysqld/sql_parse.cc to fix compilation with
  EMBEDDED_LIBRARY.

Show diffs side-by-side

added added

removed removed

Lines of Context:
342
342
  RETURN VALUE
343
343
    0 - Equal definitions.
344
344
    1 - Different definitions.
 
345
 
 
346
  TODO
 
347
    - compare FULLTEXT keys;
 
348
    - compare SPATIAL keys;
 
349
    - compare FIELD_SKIP_ZERO which is converted to FIELD_NORMAL correctly
 
350
      (should be corretly detected in table2myisam).
345
351
*/
346
352
 
347
353
int check_definition(MI_KEYDEF *t1_keyinfo, MI_COLUMNDEF *t1_recinfo,
367
373
  {
368
374
    HA_KEYSEG *t1_keysegs= t1_keyinfo[i].seg;
369
375
    HA_KEYSEG *t2_keysegs= t2_keyinfo[i].seg;
 
376
    if (t1_keyinfo[i].flag & HA_FULLTEXT && t2_keyinfo[i].flag & HA_FULLTEXT)
 
377
      continue;
 
378
    else if (t1_keyinfo[i].flag & HA_FULLTEXT ||
 
379
             t2_keyinfo[i].flag & HA_FULLTEXT)
 
380
    {
 
381
       DBUG_PRINT("error", ("Key %d has different definition", i));
 
382
       DBUG_PRINT("error", ("t1_fulltext= %d, t2_fulltext=%d",
 
383
                            test(t1_keyinfo[i].flag & HA_FULLTEXT),
 
384
                            test(t2_keyinfo[i].flag & HA_FULLTEXT)));
 
385
       DBUG_RETURN(1);
 
386
    }
 
387
    if (t1_keyinfo[i].flag & HA_SPATIAL && t2_keyinfo[i].flag & HA_SPATIAL)
 
388
      continue;
 
389
    else if (t1_keyinfo[i].flag & HA_SPATIAL ||
 
390
             t2_keyinfo[i].flag & HA_SPATIAL)
 
391
    {
 
392
       DBUG_PRINT("error", ("Key %d has different definition", i));
 
393
       DBUG_PRINT("error", ("t1_spatial= %d, t2_spatial=%d",
 
394
                            test(t1_keyinfo[i].flag & HA_SPATIAL),
 
395
                            test(t2_keyinfo[i].flag & HA_SPATIAL)));
 
396
       DBUG_RETURN(1);
 
397
    }
370
398
    if (t1_keyinfo[i].keysegs != t2_keyinfo[i].keysegs ||
371
399
        t1_keyinfo[i].key_alg != t2_keyinfo[i].key_alg)
372
400
    {
403
431
  {
404
432
    MI_COLUMNDEF *t1_rec= &t1_recinfo[i];
405
433
    MI_COLUMNDEF *t2_rec= &t2_recinfo[i];
406
 
    if (t1_rec->type != t2_rec->type ||
 
434
    /*
 
435
      FIELD_SKIP_ZERO can be changed to FIELD_NORMAL in mi_create,
 
436
      see NOTE1 in mi_create.c
 
437
    */
 
438
    if ((t1_rec->type != t2_rec->type &&
 
439
         !(t1_rec->type == (int) FIELD_SKIP_ZERO &&
 
440
           t1_rec->length == 1 &&
 
441
           t2_rec->type == (int) FIELD_NORMAL)) ||
407
442
        t1_rec->length != t2_rec->length ||
408
443
        t1_rec->null_bit != t2_rec->null_bit)
409
444
    {
638
673
  MYISAM_SHARE* share = file->s;
639
674
  const char *old_proc_info=thd->proc_info;
640
675
 
641
 
  thd_proc_info(thd, "Checking table");
 
676
  thd->proc_info="Checking table";
642
677
  myisamchk_init(&param);
643
678
  param.thd = thd;
644
679
  param.op_name =   "check";
712
747
    file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
713
748
  }
714
749
 
715
 
  thd_proc_info(thd, old_proc_info);
 
750
  thd->proc_info=old_proc_info;
716
751
  return error ? HA_ADMIN_CORRUPT : HA_ADMIN_OK;
717
752
}
718
753
 
930
965
}
931
966
 
932
967
 
933
 
int ha_myisam::repair(THD *thd, MI_CHECK &param, bool optimize)
 
968
int ha_myisam::repair(THD *thd, MI_CHECK &param, bool do_optimize)
934
969
{
935
970
  int error=0;
936
971
  uint local_testflag=param.testflag;
937
 
  bool optimize_done= !optimize, statistics_done=0;
 
972
  bool optimize_done= !do_optimize, statistics_done=0;
938
973
  const char *old_proc_info=thd->proc_info;
939
974
  char fixed_name[FN_REFLEN];
940
975
  MYISAM_SHARE* share = file->s;
958
993
    DBUG_RETURN(HA_ADMIN_FAILED);
959
994
  }
960
995
 
961
 
  if (!optimize ||
 
996
  if (!do_optimize ||
962
997
      ((file->state->del || share->state.split != file->state->records) &&
963
998
       (!(param.testflag & T_QUICK) ||
964
999
        !(share->state.changed & STATE_NOT_OPTIMIZED_KEYS))))
978
1013
        char buf[40];
979
1014
        /* TODO: respect myisam_repair_threads variable */
980
1015
        my_snprintf(buf, 40, "Repair with %d threads", my_count_bits(key_map));
981
 
        thd_proc_info(thd, buf);
 
1016
        thd->proc_info=buf;
982
1017
        error = mi_repair_parallel(&param, file, fixed_name,
983
1018
            param.testflag & T_QUICK);
984
 
        thd_proc_info(thd, "Repair done"); // to reset proc_info, as
 
1019
        thd->proc_info="Repair done"; // to reset proc_info, as
985
1020
                                      // it was pointing to local buffer
986
1021
      }
987
1022
      else
988
1023
      {
989
 
        thd_proc_info(thd, "Repair by sorting");
 
1024
        thd->proc_info="Repair by sorting";
990
1025
        error = mi_repair_by_sort(&param, file, fixed_name,
991
1026
            param.testflag & T_QUICK);
992
1027
      }
993
1028
    }
994
1029
    else
995
1030
    {
996
 
      thd_proc_info(thd, "Repair with keycache");
 
1031
      thd->proc_info="Repair with keycache";
997
1032
      param.testflag &= ~T_REP_BY_SORT;
998
1033
      error=  mi_repair(&param, file, fixed_name,
999
1034
                        param.testflag & T_QUICK);
1007
1042
        (share->state.changed & STATE_NOT_SORTED_PAGES))
1008
1043
    {
1009
1044
      optimize_done=1;
1010
 
      thd_proc_info(thd, "Sorting index");
 
1045
      thd->proc_info="Sorting index";
1011
1046
      error=mi_sort_index(&param,file,fixed_name);
1012
1047
    }
1013
1048
    if (!statistics_done && (local_testflag & T_STATISTICS))
1015
1050
      if (share->state.changed & STATE_NOT_ANALYZED)
1016
1051
      {
1017
1052
        optimize_done=1;
1018
 
        thd_proc_info(thd, "Analyzing");
 
1053
        thd->proc_info="Analyzing";
1019
1054
        error = chk_key(&param, file);
1020
1055
      }
1021
1056
      else
1022
1057
        local_testflag&= ~T_STATISTICS;         // Don't update statistics
1023
1058
    }
1024
1059
  }
1025
 
  thd_proc_info(thd, "Saving state");
 
1060
  thd->proc_info="Saving state";
1026
1061
  if (!error)
1027
1062
  {
1028
1063
    if ((share->state.changed & STATE_CHANGED) || mi_is_crashed(file))
1060
1095
    file->update |= HA_STATE_CHANGED | HA_STATE_ROW_CHANGED;
1061
1096
    update_state_info(&param, file, 0);
1062
1097
  }
1063
 
  thd_proc_info(thd, old_proc_info);
 
1098
  thd->proc_info=old_proc_info;
1064
1099
  if (!thd->locked_tables)
1065
1100
    mi_lock_database(file,F_UNLCK);
1066
1101
  DBUG_RETURN(error ? HA_ADMIN_FAILED :
1285
1320
    THD *thd=current_thd;
1286
1321
    MI_CHECK param;
1287
1322
    const char *save_proc_info=thd->proc_info;
1288
 
    thd_proc_info(thd, "Creating index");
 
1323
    thd->proc_info="Creating index";
1289
1324
    myisamchk_init(&param);
1290
1325
    param.op_name= "recreating_index";
1291
1326
    param.testflag= (T_SILENT | T_REP_BY_SORT | T_QUICK |
1310
1345
        thd->clear_error();
1311
1346
    }
1312
1347
    info(HA_STATUS_CONST);
1313
 
    thd_proc_info(thd, save_proc_info);
 
1348
    thd->proc_info=save_proc_info;
1314
1349
  }
1315
1350
  else
1316
1351
  {
1593
1628
 
1594
1629
void ha_myisam::position(const byte* record)
1595
1630
{
1596
 
  my_off_t position=mi_position(file);
1597
 
  my_store_ptr(ref, ref_length, position);
 
1631
  my_off_t row_position= mi_position(file);
 
1632
  my_store_ptr(ref, ref_length, row_position);
1598
1633
}
1599
1634
 
1600
1635
int ha_myisam::info(uint flag)
1601
1636
{
1602
 
  MI_ISAMINFO info;
 
1637
  MI_ISAMINFO misam_info;
1603
1638
  char name_buff[FN_REFLEN];
1604
1639
 
1605
 
  (void) mi_status(file,&info,flag);
 
1640
  (void) mi_status(file,&misam_info,flag);
1606
1641
  if (flag & HA_STATUS_VARIABLE)
1607
1642
  {
1608
 
    records = info.records;
1609
 
    deleted = info.deleted;
1610
 
    data_file_length=info.data_file_length;
1611
 
    index_file_length=info.index_file_length;
1612
 
    delete_length = info.delete_length;
1613
 
    check_time  = info.check_time;
1614
 
    mean_rec_length=info.mean_reclength;
 
1643
    records=           misam_info.records;
 
1644
    deleted=           misam_info.deleted;
 
1645
    data_file_length=  misam_info.data_file_length;
 
1646
    index_file_length= misam_info.index_file_length;
 
1647
    delete_length=     misam_info.delete_length;
 
1648
    check_time=        misam_info.check_time;
 
1649
    mean_rec_length= misam_info.mean_reclength;
1615
1650
  }
1616
1651
  if (flag & HA_STATUS_CONST)
1617
1652
  {
1618
1653
    TABLE_SHARE *share= table->s;
1619
 
    max_data_file_length=  info.max_data_file_length;
1620
 
    max_index_file_length= info.max_index_file_length;
1621
 
    create_time= info.create_time;
1622
 
    sortkey= info.sortkey;
1623
 
    ref_length= info.reflength;
1624
 
    share->db_options_in_use= info.options;
 
1654
    max_data_file_length=  misam_info.max_data_file_length;
 
1655
    max_index_file_length= misam_info.max_index_file_length;
 
1656
    create_time= misam_info.create_time;
 
1657
    sortkey= misam_info.sortkey;
 
1658
    ref_length= misam_info.reflength;
 
1659
    share->db_options_in_use= misam_info.options;
1625
1660
    block_size= myisam_block_size;
1626
1661
    share->keys_in_use.set_prefix(share->keys);
1627
 
    share->keys_in_use.intersect_extended(info.key_map);
 
1662
    share->keys_in_use.intersect_extended(misam_info.key_map);
1628
1663
    share->keys_for_keyread.intersect(share->keys_in_use);
1629
 
    share->db_record_offset= info.record_offset;
 
1664
    share->db_record_offset= misam_info.record_offset;
1630
1665
    if (share->key_parts)
1631
1666
      memcpy((char*) table->key_info[0].rec_per_key,
1632
 
             (char*) info.rec_per_key,
 
1667
             (char*) misam_info.rec_per_key,
1633
1668
             sizeof(table->key_info[0].rec_per_key)*share->key_parts);
1634
 
    raid_type= info.raid_type;
1635
 
    raid_chunks= info.raid_chunks;
1636
 
    raid_chunksize= info.raid_chunksize;
 
1669
    raid_type= misam_info.raid_type;
 
1670
    raid_chunks= misam_info.raid_chunks;
 
1671
    raid_chunksize= misam_info.raid_chunksize;
1637
1672
 
1638
1673
   /*
1639
1674
     Set data_file_name and index_file_name to point at the symlink value
1641
1676
   */
1642
1677
    data_file_name=index_file_name=0;
1643
1678
    fn_format(name_buff, file->filename, "", MI_NAME_DEXT, 2);
1644
 
    if (strcmp(name_buff, info.data_file_name))
1645
 
      data_file_name=info.data_file_name;
 
1679
    if (strcmp(name_buff, misam_info.data_file_name))
 
1680
      data_file_name= misam_info.data_file_name;
1646
1681
    strmov(fn_ext(name_buff),MI_NAME_IEXT);
1647
 
    if (strcmp(name_buff, info.index_file_name))
1648
 
      index_file_name=info.index_file_name;
 
1682
    if (strcmp(name_buff, misam_info.index_file_name))
 
1683
      index_file_name= misam_info.index_file_name;
1649
1684
  }
1650
1685
  if (flag & HA_STATUS_ERRKEY)
1651
1686
  {
1652
 
    errkey  = info.errkey;
1653
 
    my_store_ptr(dupp_ref, ref_length, info.dupp_key_pos);
 
1687
    errkey  = misam_info.errkey;
 
1688
    my_store_ptr(dupp_ref, ref_length, misam_info.dupp_key_pos);
1654
1689
  }
1655
1690
  if (flag & HA_STATUS_TIME)
1656
 
    update_time = info.update_time;
 
1691
    update_time = misam_info.update_time;
1657
1692
  if (flag & HA_STATUS_AUTO)
1658
 
    auto_increment_value= info.auto_increment;
 
1693
    auto_increment_value= misam_info.auto_increment;
1659
1694
 
1660
1695
  return 0;
1661
1696
}
1725
1760
 
1726
1761
 
1727
1762
int ha_myisam::create(const char *name, register TABLE *table_arg,
1728
 
                      HA_CREATE_INFO *info)
 
1763
                      HA_CREATE_INFO *ha_create_info)
1729
1764
{
1730
1765
  int error;
1731
1766
  uint create_flags= 0, records;
1742
1777
  create_info.max_rows= share->max_rows;
1743
1778
  create_info.reloc_rows= share->min_rows;
1744
1779
  create_info.with_auto_increment= share->next_number_key_offset == 0;
1745
 
  create_info.auto_increment= (info->auto_increment_value ?
1746
 
                               info->auto_increment_value -1 :
 
1780
  create_info.auto_increment= (ha_create_info->auto_increment_value ?
 
1781
                               ha_create_info->auto_increment_value -1 :
1747
1782
                               (ulonglong) 0);
1748
1783
  create_info.data_file_length= ((ulonglong) share->max_rows *
1749
1784
                                 share->avg_row_length);
1750
 
  create_info.raid_type= info->raid_type;
1751
 
  create_info.raid_chunks= (info->raid_chunks ? info->raid_chunks :
 
1785
  create_info.raid_type= ha_create_info->raid_type;
 
1786
  create_info.raid_chunks= (ha_create_info->raid_chunks ?
 
1787
                            ha_create_info->raid_chunks :
1752
1788
                            RAID_DEFAULT_CHUNKS);
1753
 
  create_info.raid_chunksize= (info->raid_chunksize ? info->raid_chunksize :
 
1789
  create_info.raid_chunksize= (ha_create_info->raid_chunksize ?
 
1790
                               ha_create_info->raid_chunksize :
1754
1791
                               RAID_DEFAULT_CHUNKSIZE);
1755
 
  create_info.data_file_name= info->data_file_name;
1756
 
  create_info.index_file_name= info->index_file_name;
 
1792
  create_info.data_file_name= ha_create_info->data_file_name;
 
1793
  create_info.index_file_name= ha_create_info->index_file_name;
1757
1794
 
1758
 
  if (info->options & HA_LEX_CREATE_TMP_TABLE)
 
1795
  if (ha_create_info->options & HA_LEX_CREATE_TMP_TABLE)
1759
1796
    create_flags|= HA_CREATE_TMP_TABLE;
1760
1797
  if (options & HA_OPTION_PACK_RECORD)
1761
1798
    create_flags|= HA_PACK_RECORD;