~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/handler.cc

  • Committer: Monty Taylor
  • Date: 2008-10-16 06:32:30 UTC
  • mto: (511.1.5 codestyle)
  • mto: This revision was merged to the branch mainline in revision 521.
  • Revision ID: monty@inaugust.com-20081016063230-4brxsra0qsmsg84q
Added -Wunused-macros.

Show diffs side-by-side

added added

removed removed

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