~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/handler.cc

  • Committer: Monty Taylor
  • Date: 2008-07-22 05:48:51 UTC
  • mto: (202.1.3 toru)
  • mto: This revision was merged to the branch mainline in revision 204.
  • Revision ID: monty@inaugust.com-20080722054851-airxt73370725p7x
Re-enabled optimizations for the normal build, and added back the --with-debug option to turn them off. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
  Handler-calling-functions
20
20
*/
21
21
 
22
 
#include <drizzled/server_includes.h>
 
22
#ifdef USE_PRAGMA_IMPLEMENTATION
 
23
#pragma implementation                          // gcc: Class implementation
 
24
#endif
 
25
 
 
26
#include "mysql_priv.h"
23
27
#include "rpl_filter.h"
24
 
#include <drizzled/drizzled_error_messages.h>
 
28
#include <myisampack.h>
 
29
#include <errno.h>
25
30
 
26
31
/*
27
32
  While we have legacy_db_type, we have this array to
34
39
 
35
40
#define BITMAP_STACKBUF_SIZE (128/8)
36
41
 
37
 
KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NULL,0}, {NULL,0} };
 
42
KEY_CREATE_INFO default_key_create_info= { HA_KEY_ALG_UNDEF, 0, {NullS,0}, {NullS,0} };
38
43
 
39
44
/* number of entries in handlertons[] */
40
45
uint32_t total_ha= 0;
47
52
{
48
53
  { C_STRING_WITH_LEN("INNOBASE") },  { C_STRING_WITH_LEN("INNODB") },
49
54
  { C_STRING_WITH_LEN("HEAP") },      { C_STRING_WITH_LEN("MEMORY") },
50
 
  {NULL, 0}
 
55
  {NullS, 0}
51
56
};
52
57
 
53
58
const char *ha_row_type[] = {
56
61
 
57
62
const char *tx_isolation_names[] =
58
63
{ "READ-UNCOMMITTED", "READ-COMMITTED", "REPEATABLE-READ", "SERIALIZABLE",
59
 
  NULL};
 
64
  NullS};
60
65
TYPELIB tx_isolation_typelib= {array_elements(tx_isolation_names)-1,"",
61
66
                               tx_isolation_names, NULL};
62
67
 
63
68
static TYPELIB known_extensions= {0,"known_exts", NULL, NULL};
64
 
uint32_t known_extensions_id= 0;
 
69
uint known_extensions_id= 0;
65
70
 
66
71
 
67
72
 
108
113
 
109
114
redo:
110
115
  /* my_strnncoll is a macro and gcc doesn't do early expansion of macro */
111
 
  if (thd && !my_charset_utf8_general_ci.coll->strnncoll(&my_charset_utf8_general_ci,
112
 
                           (const unsigned char *)name->str, name->length,
113
 
                           (const unsigned char *)STRING_WITH_LEN("DEFAULT"), 0))
 
116
  if (thd && !my_charset_latin1.coll->strnncoll(&my_charset_latin1,
 
117
                           (const uchar *)name->str, name->length,
 
118
                           (const uchar *)STRING_WITH_LEN("DEFAULT"), 0))
114
119
    return ha_default_plugin(thd);
115
120
 
116
 
  if ((plugin= my_plugin_lock_by_name(thd, name, DRIZZLE_STORAGE_ENGINE_PLUGIN)))
 
121
  if ((plugin= my_plugin_lock_by_name(thd, name, MYSQL_STORAGE_ENGINE_PLUGIN)))
117
122
  {
118
123
    handlerton *hton= plugin_data(plugin, handlerton *);
119
124
    if (!(hton->flags & HTON_NOT_USER_SELECTABLE))
130
135
  */
131
136
  for (table_alias= sys_table_aliases; table_alias->str; table_alias+= 2)
132
137
  {
133
 
    if (!my_strnncoll(&my_charset_utf8_general_ci,
134
 
                      (const unsigned char *)name->str, name->length,
135
 
                      (const unsigned char *)table_alias->str, table_alias->length))
 
138
    if (!my_strnncoll(&my_charset_latin1,
 
139
                      (const uchar *)name->str, name->length,
 
140
                      (const uchar *)table_alias->str, table_alias->length))
136
141
    {
137
142
      name= table_alias + 1;
138
143
      goto redo;
192
197
    return NULL;
193
198
  }
194
199
 
 
200
  switch (database_type) {
 
201
  case DB_TYPE_HASH:
 
202
    return ha_resolve_by_legacy_type(thd, DB_TYPE_HASH);
 
203
  default:
 
204
    break;
 
205
  }
 
206
 
195
207
  return ha_default_handlerton(thd);
196
208
} /* ha_checktype */
197
209
 
299
311
  /* Allocate a pointer array for the error message strings. */
300
312
  if (! (errmsgs= my_error_unregister(HA_ERR_FIRST, HA_ERR_LAST)))
301
313
    return 1;
302
 
  free((unsigned char*) errmsgs);
 
314
  my_free((uchar*) errmsgs, MYF(0));
303
315
  return 0;
304
316
}
305
317
 
319
331
    break;
320
332
  };
321
333
 
322
 
  if (hton && plugin->plugin->deinit)
323
 
    (void)plugin->plugin->deinit(hton);
 
334
  if (hton->panic)
 
335
    hton->panic(hton, HA_PANIC_CLOSE);
324
336
 
325
 
  free((unsigned char*)hton);
 
337
  my_free((uchar*)hton, MYF(0));
326
338
 
327
339
  return(0);
328
340
}
341
353
    structure. Apparently get_backup_engine was not NULL even though it was
342
354
    not initialized.
343
355
   */
344
 
  memset(hton, 0, sizeof(hton));
 
356
  bzero(hton, sizeof(hton));
345
357
  /* Historical Requirement */
346
358
  plugin->data= hton; // shortcut for the future
347
359
  if (plugin->plugin->init)
348
360
  {
349
361
    if (plugin->plugin->init(hton))
350
362
    {
351
 
      sql_print_error(_("Plugin '%s' init function returned error."),
 
363
      sql_print_error("Plugin '%s' init function returned error.",
352
364
                      plugin->name.str);
353
365
      goto err;
354
366
    }
363
375
    break;
364
376
  case SHOW_OPTION_YES:
365
377
    {
366
 
      uint32_t tmp;
 
378
      uint tmp;
367
379
      /* now check the db_type for conflict */
368
380
      if (hton->db_type <= DB_TYPE_UNKNOWN ||
369
381
          hton->db_type >= DB_TYPE_DEFAULT ||
376
388
 
377
389
        if (idx == (int) DB_TYPE_DEFAULT)
378
390
        {
379
 
          sql_print_warning(_("Too many storage engines!"));
 
391
          sql_print_warning("Too many storage engines!");
380
392
          return(1);
381
393
        }
382
394
        if (hton->db_type != DB_TYPE_UNKNOWN)
383
 
          sql_print_warning(_("Storage engine '%s' has conflicting typecode. "
384
 
                            "Assigning value %d."), plugin->plugin->name, idx);
 
395
          sql_print_warning("Storage engine '%s' has conflicting typecode. "
 
396
                            "Assigning value %d.", plugin->plugin->name, idx);
385
397
        hton->db_type= (enum legacy_db_type) idx;
386
398
      }
387
399
      installed_htons[hton->db_type]= hton;
405
417
    "memory" hton which will be configurable longterm. We should be able to 
406
418
    remove partition and myisammrg.
407
419
  */
408
 
  if (strcmp(plugin->plugin->name, "MEMORY") == 0)
 
420
  switch (hton->db_type) {
 
421
  case DB_TYPE_HEAP:
409
422
    heap_hton= hton;
410
 
 
411
 
  if (strcmp(plugin->plugin->name, "MyISAM") == 0)
 
423
    break;
 
424
  case DB_TYPE_MYISAM:
412
425
    myisam_hton= hton;
 
426
    break;
 
427
  default:
 
428
    break;
 
429
  };
413
430
 
414
431
  return(0);
415
432
err:
446
463
  return(error);
447
464
}
448
465
 
449
 
static bool dropdb_handlerton(THD *unused1 __attribute__((unused)),
 
466
static bool dropdb_handlerton(THD *unused1 __attribute__((__unused__)),
450
467
                              plugin_ref plugin,
451
468
                              void *path)
452
469
{
459
476
 
460
477
void ha_drop_database(char* path)
461
478
{
462
 
  plugin_foreach(NULL, dropdb_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, path);
 
479
  plugin_foreach(NULL, dropdb_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, path);
463
480
}
464
481
 
465
482
 
466
483
static bool closecon_handlerton(THD *thd, plugin_ref plugin,
467
 
                                void *unused __attribute__((unused)))
 
484
                                void *unused __attribute__((__unused__)))
468
485
{
469
486
  handlerton *hton= plugin_data(plugin, handlerton *);
470
487
  /*
484
501
*/
485
502
void ha_close_connection(THD* thd)
486
503
{
487
 
  plugin_foreach(thd, closecon_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, 0);
 
504
  plugin_foreach(thd, closecon_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, 0);
488
505
}
489
506
 
490
507
/* ========================================================================
760
777
  to maintain atomicity: if CREATE TABLE .. SELECT failed,
761
778
  the newly created table is deleted.
762
779
  In addition, some DDL statements issue interim transaction
763
 
  commits: e.g. ALTER Table issues a commit after data is copied
 
780
  commits: e.g. ALTER TABLE issues a commit after data is copied
764
781
  from the original table to the internal temporary table. Other
765
782
  statements, e.g. CREATE TABLE ... SELECT do not always commit
766
783
  after itself.
767
784
  And finally there is a group of DDL statements such as
768
 
  RENAME/DROP Table that doesn't start a new transaction
 
785
  RENAME/DROP TABLE that doesn't start a new transaction
769
786
  and doesn't commit.
770
787
 
771
788
  This diversity makes it hard to say what will happen if
850
867
      }
851
868
      else
852
869
      {
853
 
        push_warning_printf(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
870
        push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
854
871
                            ER_ILLEGAL_HA, ER(ER_ILLEGAL_HA),
855
872
                            ha_resolve_storage_engine_name(ht));
856
873
      }
950
967
  assert(thd->transaction.stmt.ha_list == NULL ||
951
968
              trans == &thd->transaction.stmt);
952
969
 
 
970
  if (thd->in_sub_stmt)
 
971
  {
 
972
    /*
 
973
      Since we don't support nested statement transactions in 5.0,
 
974
      we can't commit or rollback stmt transactions while we are inside
 
975
      stored functions or triggers. So we simply do nothing now.
 
976
      TODO: This should be fixed in later ( >= 5.1) releases.
 
977
    */
 
978
    if (!all)
 
979
      return(0);
 
980
    /*
 
981
      We assume that all statements which commit or rollback main transaction
 
982
      are prohibited inside of stored functions or triggers. So they should
 
983
      bail out with error even before ha_commit_trans() call. To be 100% safe
 
984
      let us throw error in non-debug builds.
 
985
    */
 
986
    assert(0);
 
987
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
 
988
    return(2);
 
989
  }
953
990
  if (ha_info)
954
991
  {
955
992
    bool must_2pc;
1068
1105
  assert(thd->transaction.stmt.ha_list == NULL ||
1069
1106
              trans == &thd->transaction.stmt);
1070
1107
 
 
1108
  if (thd->in_sub_stmt)
 
1109
  {
 
1110
    /*
 
1111
      If we are inside stored function or trigger we should not commit or
 
1112
      rollback current statement transaction. See comment in ha_commit_trans()
 
1113
      call for more information.
 
1114
    */
 
1115
    if (!all)
 
1116
      return(0);
 
1117
    assert(0);
 
1118
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
 
1119
    return(1);
 
1120
  }
1071
1121
  if (ha_info)
1072
1122
  {
1073
1123
    for (; ha_info; ha_info= ha_info_next)
1107
1157
  */
1108
1158
  if (is_real_trans && thd->transaction.all.modified_non_trans_table &&
1109
1159
      !thd->slave_thread && thd->killed != THD::KILL_CONNECTION)
1110
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN,
 
1160
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1111
1161
                 ER_WARNING_NOT_COMPLETE_ROLLBACK,
1112
1162
                 ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
1113
1163
  return(error);
1136
1186
    else 
1137
1187
    {
1138
1188
      (void) ha_rollback_trans(thd, 0);
1139
 
      if (thd->transaction_rollback_request)
 
1189
      if (thd->transaction_rollback_request && !thd->in_sub_stmt)
1140
1190
        (void) ha_rollback(thd);
1141
1191
    }
1142
1192
 
1151
1201
  int result;
1152
1202
};
1153
1203
 
1154
 
static bool xacommit_handlerton(THD *unused1 __attribute__((unused)),
 
1204
static bool xacommit_handlerton(THD *unused1 __attribute__((__unused__)),
1155
1205
                                plugin_ref plugin,
1156
1206
                                void *arg)
1157
1207
{
1164
1214
  return false;
1165
1215
}
1166
1216
 
1167
 
static bool xarollback_handlerton(THD *unused1 __attribute__((unused)),
 
1217
static bool xarollback_handlerton(THD *unused1 __attribute__((__unused__)),
1168
1218
                                  plugin_ref plugin,
1169
1219
                                  void *arg)
1170
1220
{
1185
1235
  xaop.result= 1;
1186
1236
 
1187
1237
  plugin_foreach(NULL, commit ? xacommit_handlerton : xarollback_handlerton,
1188
 
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &xaop);
 
1238
                 MYSQL_STORAGE_ENGINE_PLUGIN, &xaop);
1189
1239
 
1190
1240
  return xaop.result;
1191
1241
}
1214
1264
  bool dry_run;
1215
1265
};
1216
1266
 
1217
 
static bool xarecover_handlerton(THD *unused __attribute__((unused)),
 
1267
static bool xarecover_handlerton(THD *unused __attribute__((__unused__)),
1218
1268
                                 plugin_ref plugin,
1219
1269
                                 void *arg)
1220
1270
{
1226
1276
  {
1227
1277
    while ((got= hton->recover(hton, info->list, info->len)) > 0 )
1228
1278
    {
1229
 
      sql_print_information(_("Found %d prepared transaction(s) in %s"),
 
1279
      sql_print_information("Found %d prepared transaction(s) in %s",
1230
1280
                            got, ha_resolve_storage_engine_name(hton));
1231
1281
      for (int i=0; i < got; i ++)
1232
1282
      {
1244
1294
        }
1245
1295
        // recovery mode
1246
1296
        if (info->commit_list ?
1247
 
            hash_search(info->commit_list, (unsigned char *)&x, sizeof(x)) != 0 :
 
1297
            hash_search(info->commit_list, (uchar *)&x, sizeof(x)) != 0 :
1248
1298
            tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT)
1249
1299
        {
1250
1300
          hton->commit_by_xid(hton, info->list+i);
1278
1328
    return(0);
1279
1329
 
1280
1330
  if (info.commit_list)
1281
 
    sql_print_information(_("Starting crash recovery..."));
 
1331
    sql_print_information("Starting crash recovery...");
1282
1332
 
1283
1333
 
1284
1334
#ifndef WILL_BE_DELETED_LATER
1306
1356
  }
1307
1357
 
1308
1358
  plugin_foreach(NULL, xarecover_handlerton, 
1309
 
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &info);
 
1359
                 MYSQL_STORAGE_ENGINE_PLUGIN, &info);
1310
1360
 
1311
 
  free((unsigned char*)info.list);
 
1361
  my_free((uchar*)info.list, MYF(0));
1312
1362
  if (info.found_foreign_xids)
1313
 
    sql_print_warning(_("Found %d prepared XA transactions"), 
 
1363
    sql_print_warning("Found %d prepared XA transactions", 
1314
1364
                      info.found_foreign_xids);
1315
1365
  if (info.dry_run && info.found_my_xids)
1316
1366
  {
1317
 
    sql_print_error(_("Found %d prepared transactions! It means that drizzled "
1318
 
                    "was not shut down properly last time and critical "
1319
 
                    "recovery information (last binlog or %s file) was "
1320
 
                    "manually deleted after a crash. You have to start "
1321
 
                    "drizzled with the --tc-heuristic-recover switch to "
1322
 
                    "commit or rollback pending transactions."),
 
1367
    sql_print_error("Found %d prepared transactions! It means that mysqld was "
 
1368
                    "not shut down properly last time and critical recovery "
 
1369
                    "information (last binlog or %s file) was manually deleted "
 
1370
                    "after a crash. You have to start mysqld with "
 
1371
                    "--tc-heuristic-recover switch to commit or rollback "
 
1372
                    "pending transactions.",
1323
1373
                    info.found_my_xids, opt_tc_log_file);
1324
1374
    return(1);
1325
1375
  }
1326
1376
  if (info.commit_list)
1327
 
    sql_print_information(_("Crash recovery finished."));
 
1377
    sql_print_information("Crash recovery finished.");
1328
1378
  return(0);
1329
1379
}
1330
1380
 
1395
1445
    always 0
1396
1446
*/
1397
1447
static bool release_temporary_latches(THD *thd, plugin_ref plugin,
1398
 
                                      void *unused __attribute__((unused)))
 
1448
                                      void *unused __attribute__((__unused__)))
1399
1449
{
1400
1450
  handlerton *hton= plugin_data(plugin, handlerton *);
1401
1451
 
1408
1458
 
1409
1459
int ha_release_temporary_latches(THD *thd)
1410
1460
{
1411
 
  plugin_foreach(thd, release_temporary_latches, DRIZZLE_STORAGE_ENGINE_PLUGIN, 
 
1461
  plugin_foreach(thd, release_temporary_latches, MYSQL_STORAGE_ENGINE_PLUGIN, 
1412
1462
                 NULL);
1413
1463
 
1414
1464
  return 0;
1417
1467
int ha_rollback_to_savepoint(THD *thd, SAVEPOINT *sv)
1418
1468
{
1419
1469
  int error=0;
1420
 
  THD_TRANS *trans= &thd->transaction.all;
 
1470
  THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
 
1471
                                        &thd->transaction.all);
1421
1472
  Ha_trx_info *ha_info, *ha_info_next;
1422
1473
 
1423
1474
  trans->no_2pc=0;
1432
1483
    assert(ht);
1433
1484
    assert(ht->savepoint_set != 0);
1434
1485
    if ((err= ht->savepoint_rollback(ht, thd,
1435
 
                                     (unsigned char *)(sv+1)+ht->savepoint_offset)))
 
1486
                                     (uchar *)(sv+1)+ht->savepoint_offset)))
1436
1487
    { // cannot happen
1437
1488
      my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1438
1489
      error=1;
1449
1500
  {
1450
1501
    int err;
1451
1502
    handlerton *ht= ha_info->ht();
1452
 
    if ((err= ht->rollback(ht, thd, !(0))))
 
1503
    if ((err= ht->rollback(ht, thd, !thd->in_sub_stmt)))
1453
1504
    { // cannot happen
1454
1505
      my_error(ER_ERROR_DURING_ROLLBACK, MYF(0), err);
1455
1506
      error=1;
1471
1522
int ha_savepoint(THD *thd, SAVEPOINT *sv)
1472
1523
{
1473
1524
  int error=0;
1474
 
  THD_TRANS *trans= &thd->transaction.all;
 
1525
  THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
 
1526
                                        &thd->transaction.all);
1475
1527
  Ha_trx_info *ha_info= trans->ha_list;
1476
1528
  for (; ha_info; ha_info= ha_info->next())
1477
1529
  {
1484
1536
      error=1;
1485
1537
      break;
1486
1538
    }
1487
 
    if ((err= ht->savepoint_set(ht, thd, (unsigned char *)(sv+1)+ht->savepoint_offset)))
 
1539
    if ((err= ht->savepoint_set(ht, thd, (uchar *)(sv+1)+ht->savepoint_offset)))
1488
1540
    { // cannot happen
1489
1541
      my_error(ER_GET_ERRNO, MYF(0), err);
1490
1542
      error=1;
1513
1565
    if (!ht->savepoint_release)
1514
1566
      continue;
1515
1567
    if ((err= ht->savepoint_release(ht, thd,
1516
 
                                    (unsigned char *)(sv+1) + ht->savepoint_offset)))
 
1568
                                    (uchar *)(sv+1) + ht->savepoint_offset)))
1517
1569
    { // cannot happen
1518
1570
      my_error(ER_GET_ERRNO, MYF(0), err);
1519
1571
      error=1;
1539
1591
{
1540
1592
  bool warn= true;
1541
1593
 
1542
 
  plugin_foreach(thd, snapshot_handlerton, DRIZZLE_STORAGE_ENGINE_PLUGIN, &warn);
 
1594
  plugin_foreach(thd, snapshot_handlerton, MYSQL_STORAGE_ENGINE_PLUGIN, &warn);
1543
1595
 
1544
1596
  /*
1545
1597
    Same idea as when one wants to CREATE TABLE in one engine which does not
1546
1598
    exist:
1547
1599
  */
1548
1600
  if (warn)
1549
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
 
1601
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR,
1550
1602
                 "This MySQL server does not support any "
1551
1603
                 "consistent-read capable storage engine");
1552
1604
  return 0;
1553
1605
}
1554
1606
 
1555
1607
 
1556
 
static bool flush_handlerton(THD *thd __attribute__((unused)),
 
1608
static bool flush_handlerton(THD *thd __attribute__((__unused__)),
1557
1609
                             plugin_ref plugin,
1558
 
                             void *arg __attribute__((unused)))
 
1610
                             void *arg __attribute__((__unused__)))
1559
1611
{
1560
1612
  handlerton *hton= plugin_data(plugin, handlerton *);
1561
1613
  if (hton->state == SHOW_OPTION_YES && hton->flush_logs && 
1570
1622
  if (db_type == NULL)
1571
1623
  {
1572
1624
    if (plugin_foreach(NULL, flush_handlerton,
1573
 
                          DRIZZLE_STORAGE_ENGINE_PLUGIN, 0))
 
1625
                          MYSQL_STORAGE_ENGINE_PLUGIN, 0))
1574
1626
      return true;
1575
1627
  }
1576
1628
  else
1590
1642
 
1591
1643
  /* Ensure that table handler get path in lower case */
1592
1644
  if (tmp_path != path)
1593
 
    my_stpcpy(tmp_path, path);
 
1645
    strmov(tmp_path, path);
1594
1646
 
1595
1647
  /*
1596
1648
    we only should turn into lowercase database/table part
1610
1662
struct Ha_delete_table_error_handler: public Internal_error_handler
1611
1663
{
1612
1664
public:
1613
 
  virtual bool handle_error(uint32_t sql_errno,
 
1665
  virtual bool handle_error(uint sql_errno,
1614
1666
                            const char *message,
1615
 
                            DRIZZLE_ERROR::enum_warning_level level,
 
1667
                            MYSQL_ERROR::enum_warning_level level,
1616
1668
                            THD *thd);
1617
 
  char buff[DRIZZLE_ERRMSG_SIZE];
 
1669
  char buff[MYSQL_ERRMSG_SIZE];
1618
1670
};
1619
1671
 
1620
1672
 
1621
1673
bool
1622
1674
Ha_delete_table_error_handler::
1623
 
handle_error(uint32_t sql_errno  __attribute__((unused)),
 
1675
handle_error(uint sql_errno  __attribute__((__unused__)),
1624
1676
             const char *message,
1625
 
             DRIZZLE_ERROR::enum_warning_level level __attribute__((unused)),
1626
 
             THD *thd __attribute__((unused)))
 
1677
             MYSQL_ERROR::enum_warning_level level __attribute__((__unused__)),
 
1678
             THD *thd __attribute__((__unused__)))
1627
1679
{
1628
1680
  /* Grab the error message */
1629
1681
  strmake(buff, message, sizeof(buff)-1);
1641
1693
  handler *file;
1642
1694
  char tmp_path[FN_REFLEN];
1643
1695
  int error;
1644
 
  Table dummy_table;
 
1696
  TABLE dummy_table;
1645
1697
  TABLE_SHARE dummy_share;
1646
1698
 
1647
 
  memset(&dummy_table, 0, sizeof(dummy_table));
1648
 
  memset(&dummy_share, 0, sizeof(dummy_share));
 
1699
  bzero((char*) &dummy_table, sizeof(dummy_table));
 
1700
  bzero((char*) &dummy_share, sizeof(dummy_share));
1649
1701
  dummy_table.s= &dummy_share;
1650
1702
 
1651
 
  /* DB_TYPE_UNKNOWN is used in ALTER Table when renaming only .frm files */
 
1703
  /* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */
1652
1704
  if (table_type == NULL ||
1653
1705
      ! (file=get_new_handler((TABLE_SHARE*)0, thd->mem_root, table_type)))
1654
1706
    return(ENOENT);
1684
1736
      XXX: should we convert *all* errors to warnings here?
1685
1737
      What if the error is fatal?
1686
1738
    */
1687
 
    push_warning(thd, DRIZZLE_ERROR::WARN_LEVEL_ERROR, error,
 
1739
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_ERROR, error,
1688
1740
                ha_delete_table_error_handler.buff);
1689
1741
  }
1690
1742
  delete file;
1702
1754
    on this->table->mem_root and we will not be able to reclaim that memory 
1703
1755
    when the clone handler object is destroyed.
1704
1756
  */
1705
 
  if (!(new_handler->ref= (unsigned char*) alloc_root(mem_root, ALIGN_SIZE(ref_length)*2)))
 
1757
  if (!(new_handler->ref= (uchar*) alloc_root(mem_root, ALIGN_SIZE(ref_length)*2)))
1706
1758
    return NULL;
1707
1759
  if (new_handler && !new_handler->ha_open(table,
1708
1760
                                           table->s->normalized_path.str,
1709
 
                                           table->getDBStat(),
 
1761
                                           table->db_stat,
1710
1762
                                           HA_OPEN_IGNORE_IF_LOCKED))
1711
1763
    return new_handler;
1712
1764
  return NULL;
1736
1788
  Try O_RDONLY if cannot open as O_RDWR
1737
1789
  Don't wait for locks if not HA_OPEN_WAIT_IF_LOCKED is set
1738
1790
*/
1739
 
int handler::ha_open(Table *table_arg, const char *name, int mode,
 
1791
int handler::ha_open(TABLE *table_arg, const char *name, int mode,
1740
1792
                     int test_if_locked)
1741
1793
{
1742
1794
  int error;
1765
1817
    (void) extra(HA_EXTRA_NO_READCHECK);        // Not needed in SQL
1766
1818
 
1767
1819
    /* ref is already allocated for us if we're called from handler::clone() */
1768
 
    if (!ref && !(ref= (unsigned char*) alloc_root(&table->mem_root, 
 
1820
    if (!ref && !(ref= (uchar*) alloc_root(&table->mem_root, 
1769
1821
                                          ALIGN_SIZE(ref_length)*2)))
1770
1822
    {
1771
1823
      close();
1785
1837
  handlers for random position
1786
1838
*/
1787
1839
 
1788
 
int handler::rnd_pos_by_record(unsigned char *record)
 
1840
int handler::rnd_pos_by_record(uchar *record)
1789
1841
{
1790
1842
  register int error;
1791
1843
 
1804
1856
  This is never called for InnoDB tables, as these table types
1805
1857
  has the HA_STATS_RECORDS_IS_EXACT set.
1806
1858
*/
1807
 
int handler::read_first_row(unsigned char * buf, uint32_t primary_key)
 
1859
int handler::read_first_row(uchar * buf, uint primary_key)
1808
1860
{
1809
1861
  register int error;
1810
1862
 
1991
2043
  */
1992
2044
  assert(next_insert_id >= auto_inc_interval_for_cur_row.minimum());
1993
2045
 
1994
 
  if ((nr= table->next_number_field->val_int()) != 0)
 
2046
  if (((nr= table->next_number_field->val_int()) != 0) || 
 
2047
      (table->auto_increment_field_not_null && (thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)))
1995
2048
  {
1996
2049
    /*
1997
2050
      Update next_insert_id if we had already generated a value in this
2020
2073
        handler::estimation_rows_to_insert was set by
2021
2074
        handler::ha_start_bulk_insert(); if 0 it means "unknown".
2022
2075
      */
2023
 
      uint32_t nb_already_reserved_intervals=
 
2076
      uint nb_already_reserved_intervals=
2024
2077
        thd->auto_inc_intervals_in_cur_stmt_for_binlog.nb_elements();
2025
2078
      uint64_t nb_desired_values;
2026
2079
      /*
2157
2210
  @param first_value         (OUT) the first value reserved by the handler
2158
2211
  @param nb_reserved_values  (OUT) how many values the handler reserved
2159
2212
*/
2160
 
void handler::get_auto_increment(uint64_t offset __attribute__((unused)),
2161
 
                                 uint64_t increment __attribute__((unused)),
2162
 
                                 uint64_t nb_desired_values __attribute__((unused)),
 
2213
void handler::get_auto_increment(uint64_t offset __attribute__((__unused__)),
 
2214
                                 uint64_t increment __attribute__((__unused__)),
 
2215
                                 uint64_t nb_desired_values __attribute__((__unused__)),
2163
2216
                                 uint64_t *first_value,
2164
2217
                                 uint64_t *nb_reserved_values)
2165
2218
{
2183
2236
  }
2184
2237
  else
2185
2238
  {
2186
 
    unsigned char key[MAX_KEY_LENGTH];
 
2239
    uchar key[MAX_KEY_LENGTH];
2187
2240
    key_copy(key, table->record[0],
2188
2241
             table->key_info + table->s->next_number_index,
2189
2242
             table->s->next_number_key_offset);
2227
2280
}
2228
2281
 
2229
2282
 
2230
 
void handler::print_keydup_error(uint32_t key_nr, const char *msg)
 
2283
void handler::print_keydup_error(uint key_nr, const char *msg)
2231
2284
{
2232
2285
  /* Write the duplicated key in the error message */
2233
2286
  char key[MAX_KEY_LENGTH];
2243
2296
  {
2244
2297
    /* Table is opened and defined at this point */
2245
2298
    key_unpack(&str,table,(uint) key_nr);
2246
 
    uint32_t max_length=DRIZZLE_ERRMSG_SIZE-(uint) strlen(msg);
 
2299
    uint max_length=MYSQL_ERRMSG_SIZE-(uint) strlen(msg);
2247
2300
    if (str.length() >= max_length)
2248
2301
    {
2249
2302
      str.length(max_length-4);
2287
2340
    break;
2288
2341
  case HA_ERR_FOUND_DUPP_KEY:
2289
2342
  {
2290
 
    uint32_t key_nr=get_dup_key(error);
 
2343
    uint key_nr=get_dup_key(error);
2291
2344
    if ((int) key_nr >= 0)
2292
2345
    {
2293
2346
      print_keydup_error(key_nr, ER(ER_DUP_ENTRY_WITH_KEY_NAME));
2298
2351
  }
2299
2352
  case HA_ERR_FOREIGN_DUPLICATE_KEY:
2300
2353
  {
2301
 
    uint32_t key_nr= get_dup_key(error);
 
2354
    uint key_nr= get_dup_key(error);
2302
2355
    if ((int) key_nr >= 0)
2303
2356
    {
2304
 
      uint32_t max_length;
 
2357
      uint max_length;
2305
2358
      /* Write the key in the error message */
2306
2359
      char key[MAX_KEY_LENGTH];
2307
2360
      String str(key,sizeof(key),system_charset_info);
2308
2361
      /* Table is opened and defined at this point */
2309
2362
      key_unpack(&str,table,(uint) key_nr);
2310
 
      max_length= (DRIZZLE_ERRMSG_SIZE-
 
2363
      max_length= (MYSQL_ERRMSG_SIZE-
2311
2364
                   (uint) strlen(ER(ER_FOREIGN_DUPLICATE_KEY)));
2312
2365
      if (str.length() >= max_length)
2313
2366
      {
2400
2453
  case HA_ERR_DROP_INDEX_FK:
2401
2454
  {
2402
2455
    const char *ptr= "???";
2403
 
    uint32_t key_nr= get_dup_key(error);
 
2456
    uint key_nr= get_dup_key(error);
2404
2457
    if ((int) key_nr >= 0)
2405
2458
      ptr= table->key_info[key_nr].name;
2406
2459
    my_error(ER_DROP_INDEX_FK, MYF(0), ptr);
2457
2510
  @return
2458
2511
    Returns true if this is a temporary error
2459
2512
*/
2460
 
bool handler::get_error_message(int error __attribute__((unused)),
2461
 
                                String* buf __attribute__((unused)))
 
2513
bool handler::get_error_message(int error __attribute__((__unused__)),
 
2514
                                String* buf __attribute__((__unused__)))
2462
2515
{
2463
2516
  return false;
2464
2517
}
2483
2536
        if (!keypart->fieldnr)
2484
2537
          continue;
2485
2538
        Field *field= table->field[keypart->fieldnr-1];
2486
 
        if (field->type() == DRIZZLE_TYPE_BLOB)
 
2539
        if (field->type() == MYSQL_TYPE_BLOB)
2487
2540
        {
2488
2541
          if (check_opt->sql_flags & TT_FOR_UPGRADE)
2489
2542
            check_opt->flags= T_MEDIUM;
2503
2556
}
2504
2557
 
2505
2558
 
2506
 
static bool update_frm_version(Table *table)
 
2559
static bool update_frm_version(TABLE *table)
2507
2560
{
2508
2561
  char path[FN_REFLEN];
2509
2562
  File file;
2515
2568
    update frm version for temporary tables as this code doesn't support
2516
2569
    temporary tables.
2517
2570
  */
2518
 
  if (table->s->mysql_version == DRIZZLE_VERSION_ID)
 
2571
  if (table->s->mysql_version == MYSQL_VERSION_ID)
2519
2572
    return(0);
2520
2573
 
2521
 
  strxmov(path, table->s->normalized_path.str, reg_ext, NULL);
 
2574
  strxmov(path, table->s->normalized_path.str, reg_ext, NullS);
2522
2575
 
2523
 
  if ((file= my_open(path, O_RDWR, MYF(MY_WME))) >= 0)
 
2576
  if ((file= my_open(path, O_RDWR|O_BINARY, MYF(MY_WME))) >= 0)
2524
2577
  {
2525
 
    unsigned char version[4];
 
2578
    uchar version[4];
2526
2579
    char *key= table->s->table_cache_key.str;
2527
 
    uint32_t key_length= table->s->table_cache_key.length;
2528
 
    Table *entry;
 
2580
    uint key_length= table->s->table_cache_key.length;
 
2581
    TABLE *entry;
2529
2582
    HASH_SEARCH_STATE state;
2530
2583
 
2531
 
    int4store(version, DRIZZLE_VERSION_ID);
 
2584
    int4store(version, MYSQL_VERSION_ID);
2532
2585
 
2533
 
    if (pwrite(file, (unsigned char*)version, 4, 51L) == 0)
 
2586
    if (pwrite(file, (uchar*)version, 4, 51L) == 0)
2534
2587
    {
2535
2588
      result= false;
2536
2589
      goto err;
2537
2590
    }
2538
2591
 
2539
 
    for (entry=(Table*) hash_first(&open_cache,(unsigned char*) key,key_length, &state);
 
2592
    for (entry=(TABLE*) hash_first(&open_cache,(uchar*) key,key_length, &state);
2540
2593
         entry;
2541
 
         entry= (Table*) hash_next(&open_cache,(unsigned char*) key,key_length, &state))
2542
 
      entry->s->mysql_version= DRIZZLE_VERSION_ID;
 
2594
         entry= (TABLE*) hash_next(&open_cache,(uchar*) key,key_length, &state))
 
2595
      entry->s->mysql_version= MYSQL_VERSION_ID;
2543
2596
  }
2544
2597
err:
2545
2598
  if (file >= 0)
2546
 
    my_close(file,MYF(MY_WME));
 
2599
    VOID(my_close(file,MYF(MY_WME)));
2547
2600
  return(result);
2548
2601
}
2549
2602
 
2553
2606
  @return
2554
2607
    key if error because of duplicated keys
2555
2608
*/
2556
 
uint32_t handler::get_dup_key(int error)
 
2609
uint handler::get_dup_key(int error)
2557
2610
{
2558
2611
  table->file->errkey  = (uint) -1;
2559
2612
  if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
2627
2680
/**
2628
2681
  Performs checks upon the table.
2629
2682
 
2630
 
  @param thd                thread doing CHECK Table operation
 
2683
  @param thd                thread doing CHECK TABLE operation
2631
2684
  @param check_opt          options from the parser
2632
2685
 
2633
2686
  @retval
2635
2688
  @retval
2636
2689
    HA_ADMIN_NEEDS_UPGRADE    Table has structures requiring upgrade
2637
2690
  @retval
2638
 
    HA_ADMIN_NEEDS_ALTER      Table has structures requiring ALTER Table
 
2691
    HA_ADMIN_NEEDS_ALTER      Table has structures requiring ALTER TABLE
2639
2692
  @retval
2640
2693
    HA_ADMIN_NOT_IMPLEMENTED
2641
2694
*/
2643
2696
{
2644
2697
  int error;
2645
2698
 
2646
 
  if ((table->s->mysql_version >= DRIZZLE_VERSION_ID) &&
 
2699
  if ((table->s->mysql_version >= MYSQL_VERSION_ID) &&
2647
2700
      (check_opt->sql_flags & TT_FOR_UPGRADE))
2648
2701
    return 0;
2649
2702
 
2650
 
  if (table->s->mysql_version < DRIZZLE_VERSION_ID)
 
2703
  if (table->s->mysql_version < MYSQL_VERSION_ID)
2651
2704
  {
2652
2705
    if ((error= check_old_types()))
2653
2706
      return error;
2718
2771
*/
2719
2772
 
2720
2773
int
2721
 
handler::ha_bulk_update_row(const unsigned char *old_data, unsigned char *new_data,
2722
 
                            uint32_t *dup_key_found)
 
2774
handler::ha_bulk_update_row(const uchar *old_data, uchar *new_data,
 
2775
                            uint *dup_key_found)
2723
2776
{
2724
2777
  mark_trx_read_write();
2725
2778
 
2809
2862
*/
2810
2863
 
2811
2864
int
2812
 
handler::ha_disable_indexes(uint32_t mode)
 
2865
handler::ha_disable_indexes(uint mode)
2813
2866
{
2814
2867
  mark_trx_read_write();
2815
2868
 
2824
2877
*/
2825
2878
 
2826
2879
int
2827
 
handler::ha_enable_indexes(uint32_t mode)
 
2880
handler::ha_enable_indexes(uint mode)
2828
2881
{
2829
2882
  mark_trx_read_write();
2830
2883
 
2916
2969
*/
2917
2970
 
2918
2971
int
2919
 
handler::ha_create(const char *name, Table *form, HA_CREATE_INFO *info)
 
2972
handler::ha_create(const char *name, TABLE *form, HA_CREATE_INFO *info)
2920
2973
{
2921
2974
  mark_trx_read_write();
2922
2975
 
2943
2996
/**
2944
2997
  Tell the storage engine that it is allowed to "disable transaction" in the
2945
2998
  handler. It is a hint that ACID is not required - it is used in NDB for
2946
 
  ALTER Table, for example, when data are copied to temporary table.
 
2999
  ALTER TABLE, for example, when data are copied to temporary table.
2947
3000
  A storage engine may treat this hint any way it likes. NDB for example
2948
3001
  starts to commit every now and then automatically.
2949
3002
  This hint can be safely ignored.
2966
3019
  return(error);
2967
3020
}
2968
3021
 
2969
 
int handler::index_next_same(unsigned char *buf, const unsigned char *key, uint32_t keylen)
 
3022
int handler::index_next_same(uchar *buf, const uchar *key, uint keylen)
2970
3023
{
2971
3024
  int error;
2972
3025
  if (!(error=index_next(buf)))
2973
3026
  {
2974
3027
    my_ptrdiff_t ptrdiff= buf - table->record[0];
2975
 
    unsigned char *save_record_0= NULL;
 
3028
    uchar *save_record_0= NULL;
2976
3029
    KEY *key_info= NULL;
2977
3030
    KEY_PART_INFO *key_part;
2978
3031
    KEY_PART_INFO *key_part_end= NULL;
3035
3088
                    bool update_create_info)
3036
3089
{
3037
3090
  int error= 1;
3038
 
  Table table;
 
3091
  TABLE table;
3039
3092
  char name_buff[FN_REFLEN];
3040
3093
  const char *name;
3041
3094
  TABLE_SHARE share;
3047
3100
    goto err;
3048
3101
 
3049
3102
  if (update_create_info)
3050
 
    table.updateCreateInfo(create_info);
 
3103
    update_create_info_from_table(create_info, &table);
3051
3104
 
3052
3105
  name= check_lowercase_names(table.file, share.path.str, name_buff);
3053
3106
 
3054
3107
  error= table.file->ha_create(name, &table, create_info);
3055
 
  closefrm(&table, 0);
 
3108
  VOID(closefrm(&table, 0));
3056
3109
  if (error)
3057
3110
  {
3058
 
    strxmov(name_buff, db, ".", table_name, NULL);
 
3111
    strxmov(name_buff, db, ".", table_name, NullS);
3059
3112
    my_error(ER_CANT_CREATE_TABLE, MYF(ME_BELL+ME_WAITTANG), name_buff, error);
3060
3113
  }
3061
3114
err:
3079
3132
int ha_create_table_from_engine(THD* thd, const char *db, const char *name)
3080
3133
{
3081
3134
  int error;
3082
 
  unsigned char *frmblob;
 
3135
  uchar *frmblob;
3083
3136
  size_t frmlen;
3084
3137
  char path[FN_REFLEN];
3085
3138
  HA_CREATE_INFO create_info;
3086
 
  Table table;
 
3139
  TABLE table;
3087
3140
  TABLE_SHARE share;
3088
3141
 
3089
 
  memset(&create_info, 0, sizeof(create_info));
 
3142
  bzero((uchar*) &create_info,sizeof(create_info));
3090
3143
  if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
3091
3144
  {
3092
3145
    /* Table could not be discovered and thus not created */
3101
3154
  build_table_filename(path, FN_REFLEN-1, db, name, "", 0);
3102
3155
  // Save the frm file
3103
3156
  error= writefrm(path, frmblob, frmlen);
3104
 
  free(frmblob);
 
3157
  my_free(frmblob, MYF(0));
3105
3158
  if (error)
3106
3159
    return(2);
3107
3160
 
3116
3169
    return(3);
3117
3170
  }
3118
3171
 
3119
 
  table.updateCreateInfo(&create_info);
 
3172
  update_create_info_from_table(&create_info, &table);
3120
3173
  create_info.table_options|= HA_OPTION_CREATE_FROM_ENGINE;
3121
3174
 
3122
3175
  check_lowercase_names(table.file, path, path);
3123
3176
  error=table.file->ha_create(path, &table, &create_info);
3124
 
  closefrm(&table, 1);
 
3177
  VOID(closefrm(&table, 1));
3125
3178
 
3126
3179
  return(error != 0);
3127
3180
}
3146
3199
/**
3147
3200
  Init a key cache if it has not been initied before.
3148
3201
*/
3149
 
int ha_init_key_cache(const char *name __attribute__((unused)),
 
3202
int ha_init_key_cache(const char *name __attribute__((__unused__)),
3150
3203
                      KEY_CACHE *key_cache)
3151
3204
{
3152
3205
  if (!key_cache->key_cache_inited)
3153
3206
  {
3154
3207
    pthread_mutex_lock(&LOCK_global_system_variables);
3155
3208
    uint32_t tmp_buff_size= (uint32_t) key_cache->param_buff_size;
3156
 
    uint32_t tmp_block_size= (uint) key_cache->param_block_size;
3157
 
    uint32_t division_limit= key_cache->param_division_limit;
3158
 
    uint32_t age_threshold=  key_cache->param_age_threshold;
 
3209
    uint tmp_block_size= (uint) key_cache->param_block_size;
 
3210
    uint division_limit= key_cache->param_division_limit;
 
3211
    uint age_threshold=  key_cache->param_age_threshold;
3159
3212
    pthread_mutex_unlock(&LOCK_global_system_variables);
3160
3213
    return(!init_key_cache(key_cache,
3161
3214
                                tmp_block_size,
3176
3229
    pthread_mutex_lock(&LOCK_global_system_variables);
3177
3230
    long tmp_buff_size= (long) key_cache->param_buff_size;
3178
3231
    long tmp_block_size= (long) key_cache->param_block_size;
3179
 
    uint32_t division_limit= key_cache->param_division_limit;
3180
 
    uint32_t age_threshold=  key_cache->param_age_threshold;
 
3232
    uint division_limit= key_cache->param_division_limit;
 
3233
    uint age_threshold=  key_cache->param_age_threshold;
3181
3234
    pthread_mutex_unlock(&LOCK_global_system_variables);
3182
3235
    return(!resize_key_cache(key_cache, tmp_block_size,
3183
3236
                                  tmp_buff_size,
3195
3248
  if (key_cache->key_cache_inited)
3196
3249
  {
3197
3250
    pthread_mutex_lock(&LOCK_global_system_variables);
3198
 
    uint32_t division_limit= key_cache->param_division_limit;
3199
 
    uint32_t age_threshold=  key_cache->param_age_threshold;
 
3251
    uint division_limit= key_cache->param_division_limit;
 
3252
    uint age_threshold=  key_cache->param_age_threshold;
3200
3253
    pthread_mutex_unlock(&LOCK_global_system_variables);
3201
3254
    change_key_cache_param(key_cache, division_limit, age_threshold);
3202
3255
  }
3237
3290
{
3238
3291
  const char *db;
3239
3292
  const char *name;
3240
 
  unsigned char **frmblob; 
 
3293
  uchar **frmblob; 
3241
3294
  size_t *frmlen;
3242
3295
};
3243
3296
 
3256
3309
}
3257
3310
 
3258
3311
int ha_discover(THD *thd, const char *db, const char *name,
3259
 
                unsigned char **frmblob, size_t *frmlen)
 
3312
                uchar **frmblob, size_t *frmlen)
3260
3313
{
3261
3314
  int error= -1; // Table does not exist in any handler
3262
3315
  st_discover_args args= {db, name, frmblob, frmlen};
3265
3318
    return(error);
3266
3319
 
3267
3320
  if (plugin_foreach(thd, discover_handlerton,
3268
 
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &args))
 
3321
                 MYSQL_STORAGE_ENGINE_PLUGIN, &args))
3269
3322
    error= 0;
3270
3323
 
3271
3324
  if (!error)
3326
3379
{
3327
3380
  st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE};
3328
3381
  plugin_foreach(thd, table_exists_in_engine_handlerton,
3329
 
                 DRIZZLE_STORAGE_ENGINE_PLUGIN, &args);
 
3382
                 MYSQL_STORAGE_ENGINE_PLUGIN, &args);
3330
3383
  return(args.err);
3331
3384
}
3332
3385
 
3351
3404
    Estimated cost of 'index only' scan
3352
3405
*/
3353
3406
 
3354
 
double handler::index_only_read_time(uint32_t keynr, double records)
 
3407
double handler::index_only_read_time(uint keynr, double records)
3355
3408
{
3356
3409
  double read_time;
3357
 
  uint32_t keys_per_block= (stats.block_size/2/
 
3410
  uint keys_per_block= (stats.block_size/2/
3358
3411
                        (table->key_info[keynr].key_length + ref_length) + 1);
3359
3412
  read_time=((double) (records + keys_per_block-1) /
3360
3413
             (double) keys_per_block);
3398
3451
*/
3399
3452
 
3400
3453
ha_rows
3401
 
handler::multi_range_read_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
 
3454
handler::multi_range_read_info_const(uint keyno, RANGE_SEQ_IF *seq,
3402
3455
                                     void *seq_init_param,
3403
 
                                     uint32_t n_ranges_arg __attribute__((unused)),
3404
 
                                     uint32_t *bufsz, uint32_t *flags, COST_VECT *cost)
 
3456
                                     uint n_ranges_arg __attribute__((__unused__)),
 
3457
                                     uint *bufsz, uint *flags, COST_VECT *cost)
3405
3458
{
3406
3459
  KEY_MULTI_RANGE range;
3407
3460
  range_seq_t seq_it;
3408
3461
  ha_rows rows, total_rows= 0;
3409
 
  uint32_t n_ranges=0;
 
3462
  uint n_ranges=0;
3410
3463
  THD *thd= current_thd;
3411
3464
  
3412
3465
  /* Default MRR implementation doesn't need buffer */
3489
3542
    other Error or can't perform the requested scan
3490
3543
*/
3491
3544
 
3492
 
int handler::multi_range_read_info(uint32_t keyno, uint32_t n_ranges, uint32_t n_rows,
3493
 
                                   uint32_t *bufsz, uint32_t *flags, COST_VECT *cost)
 
3545
int handler::multi_range_read_info(uint keyno, uint n_ranges, uint n_rows,
 
3546
                                   uint *bufsz, uint *flags, COST_VECT *cost)
3494
3547
{
3495
3548
  *bufsz= 0; /* Default implementation doesn't need a buffer */
3496
3549
 
3551
3604
 
3552
3605
int
3553
3606
handler::multi_range_read_init(RANGE_SEQ_IF *seq_funcs, void *seq_init_param,
3554
 
                               uint32_t n_ranges, uint32_t mode,
3555
 
                               HANDLER_BUFFER *buf __attribute__((unused)))
 
3607
                               uint n_ranges, uint mode,
 
3608
                               HANDLER_BUFFER *buf __attribute__((__unused__)))
3556
3609
{
3557
3610
  mrr_iter= seq_funcs->init(seq_init_param, n_ranges, mode);
3558
3611
  mrr_funcs= *seq_funcs;
3578
3631
int handler::multi_range_read_next(char **range_info)
3579
3632
{
3580
3633
  int result= 0;
3581
 
  int range_res= 0;
 
3634
  int range_res;
3582
3635
 
3583
3636
  if (!mrr_have_range)
3584
3637
  {
3653
3706
 
3654
3707
int DsMrr_impl::dsmrr_init(handler *h, KEY *key,
3655
3708
                           RANGE_SEQ_IF *seq_funcs, void *seq_init_param,
3656
 
                           uint32_t n_ranges, uint32_t mode, HANDLER_BUFFER *buf)
 
3709
                           uint n_ranges, uint mode, HANDLER_BUFFER *buf)
3657
3710
{
3658
 
  uint32_t elem_size;
3659
 
  uint32_t keyno;
 
3711
  uint elem_size;
 
3712
  uint keyno;
3660
3713
  Item *pushed_cond= NULL;
3661
3714
  handler *new_h2;
3662
3715
  keyno= h->active_index;
3746
3799
}
3747
3800
 
3748
3801
 
3749
 
static int rowid_cmp(void *h, unsigned char *a, unsigned char *b)
 
3802
static int rowid_cmp(void *h, uchar *a, uchar *b)
3750
3803
{
3751
3804
  return ((handler*)h)->cmp_ref(a, b);
3752
3805
}
3769
3822
  @retval other  Error
3770
3823
*/
3771
3824
 
3772
 
int DsMrr_impl::dsmrr_fill_buffer(handler *unused __attribute__((unused)))
 
3825
int DsMrr_impl::dsmrr_fill_buffer(handler *unused __attribute__((__unused__)))
3773
3826
{
3774
3827
  char *range_info;
3775
 
  int res = 0;
 
3828
  int res;
3776
3829
 
3777
3830
  rowids_buf_cur= rowids_buf;
3778
3831
  while ((rowids_buf_cur < rowids_buf_end) && 
3795
3848
  dsmrr_eof= test(res == HA_ERR_END_OF_FILE);
3796
3849
 
3797
3850
  /* Sort the buffer contents by rowid */
3798
 
  uint32_t elem_size= h->ref_length + (int)is_mrr_assoc * sizeof(void*);
3799
 
  uint32_t n_rowids= (rowids_buf_cur - rowids_buf) / elem_size;
 
3851
  uint elem_size= h->ref_length + (int)is_mrr_assoc * sizeof(void*);
 
3852
  uint n_rowids= (rowids_buf_cur - rowids_buf) / elem_size;
3800
3853
  
3801
3854
  my_qsort2(rowids_buf, n_rowids, elem_size, (qsort2_cmp)rowid_cmp,
3802
3855
            (void*)h);
3854
3907
/**
3855
3908
  DS-MRR implementation: multi_range_read_info() function
3856
3909
*/
3857
 
int DsMrr_impl::dsmrr_info(uint32_t keyno, uint32_t n_ranges, uint32_t rows, uint32_t *bufsz,
3858
 
                           uint32_t *flags, COST_VECT *cost)
 
3910
int DsMrr_impl::dsmrr_info(uint keyno, uint n_ranges, uint rows, uint *bufsz,
 
3911
                           uint *flags, COST_VECT *cost)
3859
3912
{  
3860
3913
  int res;
3861
 
  uint32_t def_flags= *flags;
3862
 
  uint32_t def_bufsz= *bufsz;
 
3914
  uint def_flags= *flags;
 
3915
  uint def_bufsz= *bufsz;
3863
3916
 
3864
3917
  /* Get cost/flags/mem_usage of default MRR implementation */
3865
3918
  res= h->handler::multi_range_read_info(keyno, n_ranges, rows, &def_bufsz,
3881
3934
  DS-MRR Implementation: multi_range_read_info_const() function
3882
3935
*/
3883
3936
 
3884
 
ha_rows DsMrr_impl::dsmrr_info_const(uint32_t keyno, RANGE_SEQ_IF *seq,
3885
 
                                 void *seq_init_param, uint32_t n_ranges, 
3886
 
                                 uint32_t *bufsz, uint32_t *flags, COST_VECT *cost)
 
3937
ha_rows DsMrr_impl::dsmrr_info_const(uint keyno, RANGE_SEQ_IF *seq,
 
3938
                                 void *seq_init_param, uint n_ranges, 
 
3939
                                 uint *bufsz, uint *flags, COST_VECT *cost)
3887
3940
{
3888
3941
  ha_rows rows;
3889
 
  uint32_t def_flags= *flags;
3890
 
  uint32_t def_bufsz= *bufsz;
 
3942
  uint def_flags= *flags;
 
3943
  uint def_bufsz= *bufsz;
3891
3944
  /* Get cost/flags/mem_usage of default MRR implementation */
3892
3945
  rows= h->handler::multi_range_read_info_const(keyno, seq, seq_init_param,
3893
3946
                                                n_ranges, &def_bufsz, 
3935
3988
  @retval false  No
3936
3989
*/
3937
3990
 
3938
 
bool DsMrr_impl::key_uses_partial_cols(uint32_t keyno)
 
3991
bool DsMrr_impl::key_uses_partial_cols(uint keyno)
3939
3992
{
3940
3993
  KEY_PART_INFO *kp= table->key_info[keyno].key_part;
3941
3994
  KEY_PART_INFO *kp_end= kp + table->key_info[keyno].key_parts;
3971
4024
  @retval false  DS-MRR implementation should be used
3972
4025
*/
3973
4026
 
3974
 
bool DsMrr_impl::choose_mrr_impl(uint32_t keyno, ha_rows rows, uint32_t *flags,
3975
 
                                 uint32_t *bufsz, COST_VECT *cost)
 
4027
bool DsMrr_impl::choose_mrr_impl(uint keyno, ha_rows rows, uint *flags,
 
4028
                                 uint *bufsz, COST_VECT *cost)
3976
4029
{
3977
4030
  COST_VECT dsmrr_cost;
3978
4031
  bool res;
3988
4041
    return true;
3989
4042
  }
3990
4043
  
3991
 
  uint32_t add_len= table->key_info[keyno].key_length + h->ref_length; 
 
4044
  uint add_len= table->key_info[keyno].key_length + h->ref_length; 
3992
4045
  *bufsz -= add_len;
3993
4046
  if (get_disk_sweep_mrr_cost(keyno, rows, *flags, bufsz, &dsmrr_cost))
3994
4047
    return true;
4021
4074
}
4022
4075
 
4023
4076
 
4024
 
static void get_sort_and_sweep_cost(Table *table, ha_rows nrows, COST_VECT *cost);
 
4077
static void get_sort_and_sweep_cost(TABLE *table, ha_rows nrows, COST_VECT *cost);
4025
4078
 
4026
4079
 
4027
4080
/**
4038
4091
                 for even 1 rowid)
4039
4092
*/
4040
4093
 
4041
 
bool DsMrr_impl::get_disk_sweep_mrr_cost(uint32_t keynr, ha_rows rows, uint32_t flags,
4042
 
                                         uint32_t *buffer_size, COST_VECT *cost)
 
4094
bool DsMrr_impl::get_disk_sweep_mrr_cost(uint keynr, ha_rows rows, uint flags,
 
4095
                                         uint *buffer_size, COST_VECT *cost)
4043
4096
{
4044
4097
  uint32_t max_buff_entries, elem_size;
4045
4098
  ha_rows rows_in_full_step, rows_in_last_step;
4046
 
  uint32_t n_full_steps;
 
4099
  uint n_full_steps;
4047
4100
  double index_read_cost;
4048
4101
 
4049
4102
  elem_size= h->ref_length + sizeof(void*) * (!test(flags & HA_MRR_NO_ASSOCIATION));
4072
4125
  else
4073
4126
  {
4074
4127
    cost->zero();
4075
 
    *buffer_size= cmax((ulong)*buffer_size, 
 
4128
    *buffer_size= max(*buffer_size, 
4076
4129
                      (size_t)(1.2*rows_in_last_step) * elem_size + 
4077
4130
                      h->ref_length + table->key_info[keynr].key_length);
4078
4131
  }
4109
4162
*/
4110
4163
 
4111
4164
static 
4112
 
void get_sort_and_sweep_cost(Table *table, ha_rows nrows, COST_VECT *cost)
 
4165
void get_sort_and_sweep_cost(TABLE *table, ha_rows nrows, COST_VECT *cost)
4113
4166
{
4114
4167
  if (nrows)
4115
4168
  {
4168
4221
  @param cost         OUT  The cost.
4169
4222
*/
4170
4223
 
4171
 
void get_sweep_read_cost(Table *table, ha_rows nrows, bool interrupted, 
 
4224
void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, 
4172
4225
                         COST_VECT *cost)
4173
4226
{
4174
4227
  cost->zero();
4224
4277
int handler::read_range_first(const key_range *start_key,
4225
4278
                              const key_range *end_key,
4226
4279
                              bool eq_range_arg,
4227
 
                              bool sorted  __attribute__((unused)))
 
4280
                              bool sorted  __attribute__((__unused__)))
4228
4281
{
4229
4282
  int result;
4230
4283
 
4329
4382
  return cmp;
4330
4383
}
4331
4384
 
4332
 
int handler::index_read_idx_map(unsigned char * buf, uint32_t index, const unsigned char * key,
 
4385
int handler::index_read_idx_map(uchar * buf, uint index, const uchar * key,
4333
4386
                                key_part_map keypart_map,
4334
4387
                                enum ha_rkey_function find_flag)
4335
4388
{
4354
4407
  @retval
4355
4408
    pointer             pointer to TYPELIB structure
4356
4409
*/
4357
 
static bool exts_handlerton(THD *unused __attribute__((unused)),
 
4410
static bool exts_handlerton(THD *unused __attribute__((__unused__)),
4358
4411
                            plugin_ref plugin,
4359
4412
                            void *arg)
4360
4413
{
4394
4447
    known_extensions_id= mysys_usage_id;
4395
4448
 
4396
4449
    plugin_foreach(NULL, exts_handlerton,
4397
 
                   DRIZZLE_STORAGE_ENGINE_PLUGIN, &found_exts);
 
4450
                   MYSQL_STORAGE_ENGINE_PLUGIN, &found_exts);
4398
4451
 
4399
4452
    ext= (const char **) my_once_alloc(sizeof(char *)*
4400
4453
                                       (found_exts.elements+1),
4413
4466
}
4414
4467
 
4415
4468
 
4416
 
static bool stat_print(THD *thd, const char *type, uint32_t type_len,
4417
 
                       const char *file, uint32_t file_len,
4418
 
                       const char *status, uint32_t status_len)
 
4469
static bool stat_print(THD *thd, const char *type, uint type_len,
 
4470
                       const char *file, uint file_len,
 
4471
                       const char *status, uint status_len)
4419
4472
{
4420
4473
  Protocol *protocol= thd->protocol;
4421
4474
  protocol->prepare_for_resend();
4462
4515
  - table is not mysql.event
4463
4516
*/
4464
4517
 
4465
 
static bool check_table_binlog_row_based(THD *thd, Table *table)
 
4518
static bool check_table_binlog_row_based(THD *thd, TABLE *table)
4466
4519
{
4467
4520
  if (table->s->cached_row_logging_check == -1)
4468
4521
  {
4504
4557
{
4505
4558
  if (thd->get_binlog_table_maps() == 0)
4506
4559
  {
4507
 
    DRIZZLE_LOCK *locks[3];
 
4560
    MYSQL_LOCK *locks[3];
4508
4561
    locks[0]= thd->extra_lock;
4509
4562
    locks[1]= thd->lock;
4510
4563
    locks[2]= thd->locked_tables;
4511
 
    for (uint32_t i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
 
4564
    for (uint i= 0 ; i < sizeof(locks)/sizeof(*locks) ; ++i )
4512
4565
    {
4513
 
      DRIZZLE_LOCK const *const lock= locks[i];
 
4566
      MYSQL_LOCK const *const lock= locks[i];
4514
4567
      if (lock == NULL)
4515
4568
        continue;
4516
4569
 
4517
 
      Table **const end_ptr= lock->table + lock->table_count;
4518
 
      for (Table **table_ptr= lock->table ; 
 
4570
      TABLE **const end_ptr= lock->table + lock->table_count;
 
4571
      for (TABLE **table_ptr= lock->table ; 
4519
4572
           table_ptr != end_ptr ;
4520
4573
           ++table_ptr)
4521
4574
      {
4522
 
        Table *const table= *table_ptr;
 
4575
        TABLE *const table= *table_ptr;
4523
4576
        if (table->current_lock == F_WRLCK &&
4524
4577
            check_table_binlog_row_based(thd, table))
4525
4578
        {
4539
4592
}
4540
4593
 
4541
4594
 
4542
 
typedef bool Log_func(THD*, Table*, bool, const unsigned char*, const unsigned char*);
 
4595
typedef bool Log_func(THD*, TABLE*, bool, const uchar*, const uchar*);
4543
4596
 
4544
 
static int binlog_log_row(Table* table,
4545
 
                          const unsigned char *before_record,
4546
 
                          const unsigned char *after_record,
 
4597
static int binlog_log_row(TABLE* table,
 
4598
                          const uchar *before_record,
 
4599
                          const uchar *after_record,
4547
4600
                          Log_func *log_func)
4548
4601
{
4549
4602
  if (table->no_replicate)
4580
4633
    We cache the table flags if the locking succeeded. Otherwise, we
4581
4634
    keep them as they were when they were fetched in ha_open().
4582
4635
  */
4583
 
  DRIZZLE_EXTERNAL_LOCK(lock_type);
 
4636
  MYSQL_EXTERNAL_LOCK(lock_type);
4584
4637
 
4585
4638
  int error= external_lock(thd, lock_type);
4586
4639
  if (error == 0)
4595
4648
int handler::ha_reset()
4596
4649
{
4597
4650
  /* Check that we have called all proper deallocation functions */
4598
 
  assert((unsigned char*) table->def_read_set.bitmap +
 
4651
  assert((uchar*) table->def_read_set.bitmap +
4599
4652
              table->s->column_bitmap_size ==
4600
 
              (unsigned char*) table->def_write_set.bitmap);
 
4653
              (uchar*) table->def_write_set.bitmap);
4601
4654
  assert(bitmap_is_set_all(&table->s->all_set));
4602
4655
  assert(table->key_read == 0);
4603
4656
  /* ensure that ha_index_end / ha_rnd_end has been called */
4610
4663
}
4611
4664
 
4612
4665
 
4613
 
int handler::ha_write_row(unsigned char *buf)
 
4666
int handler::ha_write_row(uchar *buf)
4614
4667
{
4615
4668
  int error;
4616
4669
  Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
4617
 
  DRIZZLE_INSERT_ROW_START();
 
4670
  MYSQL_INSERT_ROW_START();
4618
4671
 
4619
4672
  mark_trx_read_write();
4620
4673
 
4622
4675
    return(error);
4623
4676
  if (unlikely(error= binlog_log_row(table, 0, buf, log_func)))
4624
4677
    return(error); /* purecov: inspected */
4625
 
  DRIZZLE_INSERT_ROW_END();
 
4678
  MYSQL_INSERT_ROW_END();
4626
4679
  return(0);
4627
4680
}
4628
4681
 
4629
4682
 
4630
 
int handler::ha_update_row(const unsigned char *old_data, unsigned char *new_data)
 
4683
int handler::ha_update_row(const uchar *old_data, uchar *new_data)
4631
4684
{
4632
4685
  int error;
4633
4686
  Log_func *log_func= Update_rows_log_event::binlog_row_logging_function;
4647
4700
  return 0;
4648
4701
}
4649
4702
 
4650
 
int handler::ha_delete_row(const unsigned char *buf)
 
4703
int handler::ha_delete_row(const uchar *buf)
4651
4704
{
4652
4705
  int error;
4653
4706
  Log_func *log_func= Delete_rows_log_event::binlog_row_logging_function;