~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to server/handler.cc

Standardized TRUE/FALSE, removed/replaced DBUG symbols

Show diffs side-by-side

added added

removed removed

Lines of Context:
90
90
handlerton *ha_default_handlerton(THD *thd)
91
91
{
92
92
  plugin_ref plugin= ha_default_plugin(thd);
93
 
  DBUG_ASSERT(plugin);
 
93
  assert(plugin);
94
94
  handlerton *hton= plugin_data(plugin, handlerton*);
95
 
  DBUG_ASSERT(hton);
 
95
  assert(hton);
96
96
  return hton;
97
97
}
98
98
 
212
212
                         handlerton *db_type)
213
213
{
214
214
  handler *file;
215
 
  DBUG_ENTER("get_new_handler");
216
 
  DBUG_PRINT("enter", ("alloc: 0x%lx", (long) alloc));
217
215
 
218
216
  if (db_type && db_type->state == SHOW_OPTION_YES && db_type->create)
219
217
  {
220
218
    if ((file= db_type->create(db_type, share, alloc)))
221
219
      file->init();
222
 
    DBUG_RETURN(file);
 
220
    return(file);
223
221
  }
224
222
  /*
225
223
    Try the default table type
226
224
    Here the call to current_thd() is ok as we call this function a lot of
227
225
    times but we enter this branch very seldom.
228
226
  */
229
 
  DBUG_RETURN(get_new_handler(share, alloc, ha_default_handlerton(current_thd)));
 
227
  return(get_new_handler(share, alloc, ha_default_handlerton(current_thd)));
230
228
}
231
229
 
232
230
 
321
319
int ha_finalize_handlerton(st_plugin_int *plugin)
322
320
{
323
321
  handlerton *hton= (handlerton *)plugin->data;
324
 
  DBUG_ENTER("ha_finalize_handlerton");
325
322
 
326
323
  switch (hton->state)
327
324
  {
337
334
  if (hton->panic)
338
335
    hton->panic(hton, HA_PANIC_CLOSE);
339
336
 
340
 
  if (plugin->plugin->deinit)
341
 
  {
342
 
    /*
343
 
      Today we have no defined/special behavior for uninstalling
344
 
      engine plugins.
345
 
    */
346
 
    DBUG_PRINT("info", ("Deinitializing plugin: '%s'", plugin->name.str));
347
 
    if (plugin->plugin->deinit(NULL))
348
 
    {
349
 
      DBUG_PRINT("warning", ("Plugin '%s' deinit function returned error.",
350
 
                             plugin->name.str));
351
 
    }
352
 
  }
353
 
 
354
337
  my_free((uchar*)hton, MYF(0));
355
338
 
356
 
  DBUG_RETURN(0);
 
339
  return(0);
357
340
}
358
341
 
359
342
 
360
343
int ha_initialize_handlerton(st_plugin_int *plugin)
361
344
{
362
345
  handlerton *hton;
363
 
  DBUG_ENTER("ha_initialize_handlerton");
364
 
  DBUG_PRINT("plugin", ("initialize plugin: '%s'", plugin->name.str));
365
346
 
366
347
  hton= (handlerton *)my_malloc(sizeof(handlerton),
367
348
                                MYF(MY_WME | MY_ZEROFILL));
408
389
        if (idx == (int) DB_TYPE_DEFAULT)
409
390
        {
410
391
          sql_print_warning("Too many storage engines!");
411
 
          DBUG_RETURN(1);
 
392
          return(1);
412
393
        }
413
394
        if (hton->db_type != DB_TYPE_UNKNOWN)
414
395
          sql_print_warning("Storage engine '%s' has conflicting typecode. "
447
428
    break;
448
429
  };
449
430
 
450
 
  DBUG_RETURN(0);
 
431
  return(0);
451
432
err:
452
 
  DBUG_RETURN(1);
 
433
  return(1);
453
434
}
454
435
 
455
436
int ha_init()
456
437
{
457
438
  int error= 0;
458
 
  DBUG_ENTER("ha_init");
459
439
 
460
 
  DBUG_ASSERT(total_ha < MAX_HA);
 
440
  assert(total_ha < MAX_HA);
461
441
  /*
462
442
    Check if there is a transaction-capable storage engine besides the
463
443
    binary log (which is considered a transaction-capable storage engine in
465
445
  */
466
446
  opt_using_transactions= total_ha>(uint32_t)opt_bin_log;
467
447
  savepoint_alloc_size+= sizeof(SAVEPOINT);
468
 
  DBUG_RETURN(error);
 
448
  return(error);
469
449
}
470
450
 
471
451
int ha_end()
472
452
{
473
453
  int error= 0;
474
 
  DBUG_ENTER("ha_end");
475
 
 
476
454
 
477
455
  /* 
478
456
    This should be eventualy based  on the graceful shutdown flag.
482
460
  if (ha_finish_errors())
483
461
    error= 1;
484
462
 
485
 
  DBUG_RETURN(error);
 
463
  return(error);
486
464
}
487
465
 
488
466
static my_bool dropdb_handlerton(THD *unused1 __attribute__((__unused__)),
836
814
{
837
815
  THD_TRANS *trans;
838
816
  Ha_trx_info *ha_info;
839
 
  DBUG_ENTER("trans_register_ha");
840
 
  DBUG_PRINT("enter",("%s", all ? "all" : "stmt"));
841
817
 
842
818
  if (all)
843
819
  {
850
826
  ha_info= thd->ha_data[ht_arg->slot].ha_info + static_cast<unsigned>(all);
851
827
 
852
828
  if (ha_info->is_started())
853
 
    DBUG_VOID_RETURN; /* already registered, return */
 
829
    return; /* already registered, return */
854
830
 
855
831
  ha_info->register_ha(trans, ht_arg);
856
832
 
858
834
  if (thd->transaction.xid_state.xid.is_null())
859
835
    thd->transaction.xid_state.xid.set(thd->query_id);
860
836
 
861
 
  DBUG_VOID_RETURN;
 
837
  return;
862
838
}
863
839
 
864
840
/**
872
848
  int error=0, all=1;
873
849
  THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
874
850
  Ha_trx_info *ha_info= trans->ha_list;
875
 
  DBUG_ENTER("ha_prepare");
876
851
  if (ha_info)
877
852
  {
878
853
    for (; ha_info; ha_info= ha_info->next())
898
873
      }
899
874
    }
900
875
  }
901
 
  DBUG_RETURN(error);
 
876
  return(error);
902
877
}
903
878
 
904
879
/**
932
907
    if (! all)
933
908
    {
934
909
      Ha_trx_info *ha_info_all= &thd->ha_data[ha_info->ht()->slot].ha_info[1];
935
 
      DBUG_ASSERT(ha_info != ha_info_all);
 
910
      assert(ha_info != ha_info_all);
936
911
      /*
937
912
        Merge read-only/read-write information about statement
938
913
        transaction to its enclosing normal transaction. Do this
982
957
  bool is_real_trans= all || thd->transaction.all.ha_list == 0;
983
958
  Ha_trx_info *ha_info= trans->ha_list;
984
959
  my_xid xid= thd->transaction.xid_state.xid.get_my_xid();
985
 
  DBUG_ENTER("ha_commit_trans");
986
960
 
987
961
  /*
988
962
    We must not commit the normal transaction if a statement
990
964
    flags will not get propagated to its normal transaction's
991
965
    counterpart.
992
966
  */
993
 
  DBUG_ASSERT(thd->transaction.stmt.ha_list == NULL ||
 
967
  assert(thd->transaction.stmt.ha_list == NULL ||
994
968
              trans == &thd->transaction.stmt);
995
969
 
996
970
  if (thd->in_sub_stmt)
1002
976
      TODO: This should be fixed in later ( >= 5.1) releases.
1003
977
    */
1004
978
    if (!all)
1005
 
      DBUG_RETURN(0);
 
979
      return(0);
1006
980
    /*
1007
981
      We assume that all statements which commit or rollback main transaction
1008
982
      are prohibited inside of stored functions or triggers. So they should
1009
983
      bail out with error even before ha_commit_trans() call. To be 100% safe
1010
984
      let us throw error in non-debug builds.
1011
985
    */
1012
 
    DBUG_ASSERT(0);
 
986
    assert(0);
1013
987
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
1014
 
    DBUG_RETURN(2);
 
988
    return(2);
1015
989
  }
1016
990
  if (ha_info)
1017
991
  {
1020
994
    if (is_real_trans && wait_if_global_read_lock(thd, 0, 0))
1021
995
    {
1022
996
      ha_rollback_trans(thd, all);
1023
 
      DBUG_RETURN(1);
 
997
      return(1);
1024
998
    }
1025
999
 
1026
1000
    if (   is_real_trans
1060
1034
        }
1061
1035
        status_var_increment(thd->status_var.ha_prepare_count);
1062
1036
      }
1063
 
      DBUG_EXECUTE_IF("crash_commit_after_prepare", abort(););
1064
1037
      if (error || (is_real_trans && xid &&
1065
1038
                    (error= !(cookie= tc_log->log_xid(thd, xid)))))
1066
1039
      {
1068
1041
        error= 1;
1069
1042
        goto end;
1070
1043
      }
1071
 
      DBUG_EXECUTE_IF("crash_commit_after_log", abort(););
1072
1044
    }
1073
1045
    error=ha_commit_one_phase(thd, all) ? (cookie ? 2 : 1) : 0;
1074
 
    DBUG_EXECUTE_IF("crash_commit_before_unlog", abort(););
1075
1046
    if (cookie)
1076
1047
      tc_log->unlog(cookie, xid);
1077
 
    DBUG_EXECUTE_IF("crash_commit_after", abort(););
1078
1048
end:
1079
1049
    if (is_real_trans)
1080
1050
      start_waiting_global_read_lock(thd);
1081
1051
  }
1082
 
  DBUG_RETURN(error);
 
1052
  return(error);
1083
1053
}
1084
1054
 
1085
1055
/**
1092
1062
  THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1093
1063
  bool is_real_trans=all || thd->transaction.all.ha_list == 0;
1094
1064
  Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
1095
 
  DBUG_ENTER("ha_commit_one_phase");
1096
1065
  if (ha_info)
1097
1066
  {
1098
1067
    for (; ha_info; ha_info= ha_info_next)
1118
1087
      thd->transaction.cleanup();
1119
1088
    }
1120
1089
  }
1121
 
  DBUG_RETURN(error);
 
1090
  return(error);
1122
1091
}
1123
1092
 
1124
1093
 
1128
1097
  THD_TRANS *trans=all ? &thd->transaction.all : &thd->transaction.stmt;
1129
1098
  Ha_trx_info *ha_info= trans->ha_list, *ha_info_next;
1130
1099
  bool is_real_trans=all || thd->transaction.all.ha_list == 0;
1131
 
  DBUG_ENTER("ha_rollback_trans");
1132
1100
 
1133
1101
  /*
1134
1102
    We must not rollback the normal transaction if a statement
1135
1103
    transaction is pending.
1136
1104
  */
1137
 
  DBUG_ASSERT(thd->transaction.stmt.ha_list == NULL ||
 
1105
  assert(thd->transaction.stmt.ha_list == NULL ||
1138
1106
              trans == &thd->transaction.stmt);
1139
1107
 
1140
1108
  if (thd->in_sub_stmt)
1145
1113
      call for more information.
1146
1114
    */
1147
1115
    if (!all)
1148
 
      DBUG_RETURN(0);
1149
 
    DBUG_ASSERT(0);
 
1116
      return(0);
 
1117
    assert(0);
1150
1118
    my_error(ER_COMMIT_NOT_ALLOWED_IN_SF_OR_TRG, MYF(0));
1151
 
    DBUG_RETURN(1);
 
1119
    return(1);
1152
1120
  }
1153
1121
  if (ha_info)
1154
1122
  {
1192
1160
    push_warning(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
1193
1161
                 ER_WARNING_NOT_COMPLETE_ROLLBACK,
1194
1162
                 ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
1195
 
  DBUG_RETURN(error);
 
1163
  return(error);
1196
1164
}
1197
1165
 
1198
1166
/**
1208
1176
*/
1209
1177
int ha_autocommit_or_rollback(THD *thd, int error)
1210
1178
{
1211
 
  DBUG_ENTER("ha_autocommit_or_rollback");
1212
1179
  if (thd->transaction.stmt.ha_list)
1213
1180
  {
1214
1181
    if (!error)
1225
1192
 
1226
1193
    thd->variables.tx_isolation=thd->session_tx_isolation;
1227
1194
  }
1228
 
  DBUG_RETURN(error);
 
1195
  return(error);
1229
1196
}
1230
1197
 
1231
1198
 
1273
1240
  return xaop.result;
1274
1241
}
1275
1242
 
1276
 
 
1277
 
#ifndef DBUG_OFF
1278
 
/**
1279
 
  @note
1280
 
    This does not need to be multi-byte safe or anything
1281
 
*/
1282
 
static char* xid_to_str(char *buf, XID *xid)
1283
 
{
1284
 
  int i;
1285
 
  char *s=buf;
1286
 
  *s++='\'';
1287
 
  for (i=0; i < xid->gtrid_length+xid->bqual_length; i++)
1288
 
  {
1289
 
    uchar c=(uchar)xid->data[i];
1290
 
    /* is_next_dig is set if next character is a number */
1291
 
    bool is_next_dig= false;
1292
 
    if (i < XIDDATASIZE)
1293
 
    {
1294
 
      char ch= xid->data[i+1];
1295
 
      is_next_dig= (ch >= '0' && ch <='9');
1296
 
    }
1297
 
    if (i == xid->gtrid_length)
1298
 
    {
1299
 
      *s++='\'';
1300
 
      if (xid->bqual_length)
1301
 
      {
1302
 
        *s++='.';
1303
 
        *s++='\'';
1304
 
      }
1305
 
    }
1306
 
    if (c < 32 || c > 126)
1307
 
    {
1308
 
      *s++='\\';
1309
 
      /*
1310
 
        If next character is a number, write current character with
1311
 
        3 octal numbers to ensure that the next number is not seen
1312
 
        as part of the octal number
1313
 
      */
1314
 
      if (c > 077 || is_next_dig)
1315
 
        *s++=_dig_vec_lower[c >> 6];
1316
 
      if (c > 007 || is_next_dig)
1317
 
        *s++=_dig_vec_lower[(c >> 3) & 7];
1318
 
      *s++=_dig_vec_lower[c & 7];
1319
 
    }
1320
 
    else
1321
 
    {
1322
 
      if (c == '\'' || c == '\\')
1323
 
        *s++='\\';
1324
 
      *s++=c;
1325
 
    }
1326
 
  }
1327
 
  *s++='\'';
1328
 
  *s=0;
1329
 
  return buf;
1330
 
}
1331
 
#endif
1332
 
 
1333
1243
/**
1334
1244
  recover() step of xa.
1335
1245
 
1373
1283
        my_xid x=info->list[i].get_my_xid();
1374
1284
        if (!x) // not "mine" - that is generated by external TM
1375
1285
        {
1376
 
#ifndef DBUG_OFF
1377
 
          char buf[XIDDATASIZE*4+6]; // see xid_to_str
1378
 
          sql_print_information("ignore xid %s", xid_to_str(buf, info->list+i));
1379
 
#endif
1380
1286
          xid_cache_insert(info->list+i, XA_PREPARED);
1381
1287
          info->found_foreign_xids++;
1382
1288
          continue;
1391
1297
            hash_search(info->commit_list, (uchar *)&x, sizeof(x)) != 0 :
1392
1298
            tc_heuristic_recover == TC_HEURISTIC_RECOVER_COMMIT)
1393
1299
        {
1394
 
#ifndef DBUG_OFF
1395
 
          char buf[XIDDATASIZE*4+6]; // see xid_to_str
1396
 
          sql_print_information("commit xid %s", xid_to_str(buf, info->list+i));
1397
 
#endif
1398
1300
          hton->commit_by_xid(hton, info->list+i);
1399
1301
        }
1400
1302
        else
1401
1303
        {
1402
 
#ifndef DBUG_OFF
1403
 
          char buf[XIDDATASIZE*4+6]; // see xid_to_str
1404
 
          sql_print_information("rollback xid %s",
1405
 
                                xid_to_str(buf, info->list+i));
1406
 
#endif
1407
1304
          hton->rollback_by_xid(hton, info->list+i);
1408
1305
        }
1409
1306
      }
1417
1314
int ha_recover(HASH *commit_list)
1418
1315
{
1419
1316
  struct xarecover_st info;
1420
 
  DBUG_ENTER("ha_recover");
1421
1317
  info.found_foreign_xids= info.found_my_xids= 0;
1422
1318
  info.commit_list= commit_list;
1423
1319
  info.dry_run= (info.commit_list==0 && tc_heuristic_recover==0);
1424
1320
  info.list= NULL;
1425
1321
 
1426
1322
  /* commit_list and tc_heuristic_recover cannot be set both */
1427
 
  DBUG_ASSERT(info.commit_list==0 || tc_heuristic_recover==0);
 
1323
  assert(info.commit_list==0 || tc_heuristic_recover==0);
1428
1324
  /* if either is set, total_ha_2pc must be set too */
1429
 
  DBUG_ASSERT(info.dry_run || total_ha_2pc>(uint32_t)opt_bin_log);
 
1325
  assert(info.dry_run || total_ha_2pc>(uint32_t)opt_bin_log);
1430
1326
 
1431
1327
  if (total_ha_2pc <= (uint32_t)opt_bin_log)
1432
 
    DBUG_RETURN(0);
 
1328
    return(0);
1433
1329
 
1434
1330
  if (info.commit_list)
1435
1331
    sql_print_information("Starting crash recovery...");
1442
1338
    rollback all pending transactions, without risking inconsistent data
1443
1339
  */
1444
1340
 
1445
 
  DBUG_ASSERT(total_ha_2pc == (uint32_t) opt_bin_log+1); // only InnoDB and binlog
 
1341
  assert(total_ha_2pc == (uint32_t) opt_bin_log+1); // only InnoDB and binlog
1446
1342
  tc_heuristic_recover= TC_HEURISTIC_RECOVER_ROLLBACK; // forcing ROLLBACK
1447
1343
  info.dry_run=false;
1448
1344
#endif
1456
1352
  if (!info.list)
1457
1353
  {
1458
1354
    sql_print_error(ER(ER_OUTOFMEMORY), info.len*sizeof(XID));
1459
 
    DBUG_RETURN(1);
 
1355
    return(1);
1460
1356
  }
1461
1357
 
1462
1358
  plugin_foreach(NULL, xarecover_handlerton, 
1475
1371
                    "--tc-heuristic-recover switch to commit or rollback "
1476
1372
                    "pending transactions.",
1477
1373
                    info.found_my_xids, opt_tc_log_file);
1478
 
    DBUG_RETURN(1);
 
1374
    return(1);
1479
1375
  }
1480
1376
  if (info.commit_list)
1481
1377
    sql_print_information("Crash recovery finished.");
1482
 
  DBUG_RETURN(0);
 
1378
  return(0);
1483
1379
}
1484
1380
 
1485
1381
/**
1496
1392
  Protocol *protocol= thd->protocol;
1497
1393
  int i=0;
1498
1394
  XID_STATE *xs;
1499
 
  DBUG_ENTER("mysql_xa_recover");
1500
1395
 
1501
1396
  field_list.push_back(new Item_int("formatID", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1502
1397
  field_list.push_back(new Item_int("gtrid_length", 0, MY_INT32_NUM_DECIMAL_DIGITS));
1505
1400
 
1506
1401
  if (protocol->send_fields(&field_list,
1507
1402
                            Protocol::SEND_NUM_ROWS | Protocol::SEND_EOF))
1508
 
    DBUG_RETURN(1);
 
1403
    return(1);
1509
1404
 
1510
1405
  pthread_mutex_lock(&LOCK_xid_cache);
1511
1406
  while ((xs= (XID_STATE*)hash_element(&xid_cache, i++)))
1521
1416
      if (protocol->write())
1522
1417
      {
1523
1418
        pthread_mutex_unlock(&LOCK_xid_cache);
1524
 
        DBUG_RETURN(1);
 
1419
        return(1);
1525
1420
      }
1526
1421
    }
1527
1422
  }
1528
1423
 
1529
1424
  pthread_mutex_unlock(&LOCK_xid_cache);
1530
1425
  my_eof(thd);
1531
 
  DBUG_RETURN(0);
 
1426
  return(0);
1532
1427
}
1533
1428
 
1534
1429
/**
1576
1471
                                        &thd->transaction.all);
1577
1472
  Ha_trx_info *ha_info, *ha_info_next;
1578
1473
 
1579
 
  DBUG_ENTER("ha_rollback_to_savepoint");
1580
 
 
1581
1474
  trans->no_2pc=0;
1582
1475
  /*
1583
1476
    rolling back to savepoint in all storage engines that were part of the
1587
1480
  {
1588
1481
    int err;
1589
1482
    handlerton *ht= ha_info->ht();
1590
 
    DBUG_ASSERT(ht);
1591
 
    DBUG_ASSERT(ht->savepoint_set != 0);
 
1483
    assert(ht);
 
1484
    assert(ht->savepoint_set != 0);
1592
1485
    if ((err= ht->savepoint_rollback(ht, thd,
1593
1486
                                     (uchar *)(sv+1)+ht->savepoint_offset)))
1594
1487
    { // cannot happen
1617
1510
    ha_info->reset(); /* keep it conveniently zero-filled */
1618
1511
  }
1619
1512
  trans->ha_list= sv->ha_list;
1620
 
  DBUG_RETURN(error);
 
1513
  return(error);
1621
1514
}
1622
1515
 
1623
1516
/**
1632
1525
  THD_TRANS *trans= (thd->in_sub_stmt ? &thd->transaction.stmt :
1633
1526
                                        &thd->transaction.all);
1634
1527
  Ha_trx_info *ha_info= trans->ha_list;
1635
 
  DBUG_ENTER("ha_savepoint");
1636
1528
  for (; ha_info; ha_info= ha_info->next())
1637
1529
  {
1638
1530
    int err;
1639
1531
    handlerton *ht= ha_info->ht();
1640
 
    DBUG_ASSERT(ht);
 
1532
    assert(ht);
1641
1533
    if (! ht->savepoint_set)
1642
1534
    {
1643
1535
      my_error(ER_CHECK_NOT_IMPLEMENTED, MYF(0), "SAVEPOINT");
1656
1548
    engines are prepended to the beginning of the list.
1657
1549
  */
1658
1550
  sv->ha_list= trans->ha_list;
1659
 
  DBUG_RETURN(error);
 
1551
  return(error);
1660
1552
}
1661
1553
 
1662
1554
int ha_release_savepoint(THD *thd, SAVEPOINT *sv)
1663
1555
{
1664
1556
  int error=0;
1665
1557
  Ha_trx_info *ha_info= sv->ha_list;
1666
 
  DBUG_ENTER("ha_release_savepoint");
1667
1558
 
1668
1559
  for (; ha_info; ha_info= ha_info->next())
1669
1560
  {
1670
1561
    int err;
1671
1562
    handlerton *ht= ha_info->ht();
1672
1563
    /* Savepoint life time is enclosed into transaction life time. */
1673
 
    DBUG_ASSERT(ht);
 
1564
    assert(ht);
1674
1565
    if (!ht->savepoint_release)
1675
1566
      continue;
1676
1567
    if ((err= ht->savepoint_release(ht, thd,
1680
1571
      error=1;
1681
1572
    }
1682
1573
  }
1683
 
  DBUG_RETURN(error);
 
1574
  return(error);
1684
1575
}
1685
1576
 
1686
1577
 
1805
1696
  int error;
1806
1697
  TABLE dummy_table;
1807
1698
  TABLE_SHARE dummy_share;
1808
 
  DBUG_ENTER("ha_delete_table");
1809
1699
 
1810
1700
  bzero((char*) &dummy_table, sizeof(dummy_table));
1811
1701
  bzero((char*) &dummy_share, sizeof(dummy_share));
1814
1704
  /* DB_TYPE_UNKNOWN is used in ALTER TABLE when renaming only .frm files */
1815
1705
  if (table_type == NULL ||
1816
1706
      ! (file=get_new_handler((TABLE_SHARE*)0, thd->mem_root, table_type)))
1817
 
    DBUG_RETURN(ENOENT);
 
1707
    return(ENOENT);
1818
1708
 
1819
1709
  path= check_lowercase_names(file, path, tmp_path);
1820
1710
  if ((error= file->ha_delete_table(path)) && generate_warning)
1851
1741
                ha_delete_table_error_handler.buff);
1852
1742
  }
1853
1743
  delete file;
1854
 
  DBUG_RETURN(error);
 
1744
  return(error);
1855
1745
}
1856
1746
 
1857
1747
/****************************************************************************
1889
1779
 
1890
1780
THD *handler::ha_thd(void) const
1891
1781
{
1892
 
  DBUG_ASSERT(!table || !table->in_use || table->in_use == current_thd);
 
1782
  assert(!table || !table->in_use || table->in_use == current_thd);
1893
1783
  return (table && table->in_use) ? table->in_use : current_thd;
1894
1784
}
1895
1785
 
1903
1793
                     int test_if_locked)
1904
1794
{
1905
1795
  int error;
1906
 
  DBUG_ENTER("handler::ha_open");
1907
 
  DBUG_PRINT("enter",
1908
 
             ("name: %s  db_type: %d  db_stat: %d  mode: %d  lock_test: %d",
1909
 
              name, ht->db_type, table_arg->db_stat, mode,
1910
 
              test_if_locked));
1911
1796
 
1912
1797
  table= table_arg;
1913
 
  DBUG_ASSERT(table->s == table_share);
1914
 
  DBUG_ASSERT(alloc_root_inited(&table->mem_root));
 
1798
  assert(table->s == table_share);
 
1799
  assert(alloc_root_inited(&table->mem_root));
1915
1800
 
1916
1801
  if ((error=open(name,mode,test_if_locked)))
1917
1802
  {
1925
1810
  if (error)
1926
1811
  {
1927
1812
    my_errno= error;                            /* Safeguard */
1928
 
    DBUG_PRINT("error",("error: %d  errno: %d",error,errno));
1929
1813
  }
1930
1814
  else
1931
1815
  {
1944
1828
      dup_ref=ref+ALIGN_SIZE(ref_length);
1945
1829
    cached_table_flags= table_flags();
1946
1830
  }
1947
 
  DBUG_RETURN(error);
 
1831
  return(error);
1948
1832
}
1949
1833
 
1950
1834
/**
1957
1841
int handler::rnd_pos_by_record(uchar *record)
1958
1842
{
1959
1843
  register int error;
1960
 
  DBUG_ENTER("handler::rnd_pos_by_record");
1961
1844
 
1962
1845
  position(record);
1963
1846
  if (inited && (error= ha_index_end()))
1964
 
    DBUG_RETURN(error);
 
1847
    return(error);
1965
1848
  if ((error= ha_rnd_init(false)))
1966
 
    DBUG_RETURN(error);
 
1849
    return(error);
1967
1850
 
1968
 
  DBUG_RETURN(rnd_pos(record, ref));
 
1851
  return(rnd_pos(record, ref));
1969
1852
}
1970
1853
 
1971
1854
/**
1977
1860
int handler::read_first_row(uchar * buf, uint primary_key)
1978
1861
{
1979
1862
  register int error;
1980
 
  DBUG_ENTER("handler::read_first_row");
1981
1863
 
1982
1864
  ha_statistic_increment(&SSV::ha_read_first_count);
1983
1865
 
2000
1882
    error=index_first(buf);
2001
1883
    (void) ha_index_end();
2002
1884
  }
2003
 
  DBUG_RETURN(error);
 
1885
  return(error);
2004
1886
}
2005
1887
 
2006
1888
/**
2064
1946
      the offset is larger than the column's max possible value, i.e. not even
2065
1947
      the first sequence value may be inserted. User will receive warning.
2066
1948
    */
2067
 
    DBUG_PRINT("info",("auto_increment: nr: %lu cannot honour "
2068
 
                       "auto_increment_offset: %lu",
2069
 
                       (uint32_t) nr, variables->auto_increment_offset));
2070
1949
    return nr;
2071
1950
  }
2072
1951
  if (variables->auto_increment_increment == 1)
2158
2037
  bool append= false;
2159
2038
  THD *thd= table->in_use;
2160
2039
  struct system_variables *variables= &thd->variables;
2161
 
  DBUG_ENTER("handler::update_auto_increment");
2162
2040
 
2163
2041
  /*
2164
2042
    next_insert_id is a "cursor" into the reserved interval, it may go greater
2165
2043
    than the interval, but not smaller.
2166
2044
  */
2167
 
  DBUG_ASSERT(next_insert_id >= auto_inc_interval_for_cur_row.minimum());
 
2045
  assert(next_insert_id >= auto_inc_interval_for_cur_row.minimum());
2168
2046
 
2169
2047
  if (((nr= table->next_number_field->val_int()) != 0) || 
2170
2048
      (table->auto_increment_field_not_null && (thd->variables.sql_mode & MODE_NO_AUTO_VALUE_ON_ZERO)))
2177
2055
    */
2178
2056
    adjust_next_insert_id_after_explicit_value(nr);
2179
2057
    insert_id_for_cur_row= 0; // didn't generate anything
2180
 
    DBUG_RETURN(0);
 
2058
    return(0);
2181
2059
  }
2182
2060
 
2183
2061
  if ((nr= next_insert_id) >= auto_inc_interval_for_cur_row.maximum())
2231
2109
                         nb_desired_values, &nr,
2232
2110
                         &nb_reserved_values);
2233
2111
      if (nr == ~(uint64_t) 0)
2234
 
        DBUG_RETURN(HA_ERR_AUTOINC_READ_FAILED);  // Mark failure
 
2112
        return(HA_ERR_AUTOINC_READ_FAILED);  // Mark failure
2235
2113
      
2236
2114
      /*
2237
2115
        That rounding below should not be needed when all engines actually
2249
2127
      /* We must defer the appending until "nr" has been possibly truncated */
2250
2128
      append= true;
2251
2129
    }
2252
 
    else
2253
 
    {
2254
 
      /*
2255
 
        For such auto_increment there is no notion of interval, just a
2256
 
        singleton. The interval is not even stored in
2257
 
        thd->auto_inc_interval_for_cur_row, so we are sure to call the engine
2258
 
        for next row.
2259
 
      */
2260
 
      DBUG_PRINT("info",("auto_increment: special not-first-in-index"));
2261
 
    }
2262
2130
  }
2263
2131
 
2264
 
  DBUG_PRINT("info",("auto_increment: %lu", (uint32_t) nr));
2265
 
 
2266
2132
  if (unlikely(table->next_number_field->store((longlong) nr, true)))
2267
2133
  {
2268
2134
    /*
2269
2135
      first test if the query was aborted due to strict mode constraints
2270
2136
    */
2271
2137
    if (thd->killed == THD::KILL_BAD_DATA)
2272
 
      DBUG_RETURN(HA_ERR_AUTOINC_ERANGE);
 
2138
      return(HA_ERR_AUTOINC_ERANGE);
2273
2139
 
2274
2140
    /*
2275
2141
      field refused this value (overflow) and truncated it, use the result of
2308
2174
  */
2309
2175
  set_next_insert_id(compute_next_insert_id(nr, variables));
2310
2176
 
2311
 
  DBUG_RETURN(0);
 
2177
  return(0);
2312
2178
}
2313
2179
 
2314
2180
 
2326
2192
*/
2327
2193
void handler::column_bitmaps_signal()
2328
2194
{
2329
 
  DBUG_ENTER("column_bitmaps_signal");
2330
 
  DBUG_PRINT("info", ("read_set: 0x%lx  write_set: 0x%lx", (long) table->read_set,
2331
 
                      (long) table->write_set));
2332
 
  DBUG_VOID_RETURN;
 
2195
  return;
2333
2196
}
2334
2197
 
2335
2198
 
2457
2320
*/
2458
2321
void handler::print_error(int error, myf errflag)
2459
2322
{
2460
 
  DBUG_ENTER("handler::print_error");
2461
 
  DBUG_PRINT("enter",("error: %d",error));
2462
 
 
2463
2323
  int textno=ER_GET_ERRNO;
2464
2324
  switch (error) {
2465
2325
  case EACCES:
2485
2345
    if ((int) key_nr >= 0)
2486
2346
    {
2487
2347
      print_keydup_error(key_nr, ER(ER_DUP_ENTRY_WITH_KEY_NAME));
2488
 
      DBUG_VOID_RETURN;
 
2348
      return;
2489
2349
    }
2490
2350
    textno=ER_DUP_KEY;
2491
2351
    break;
2510
2370
      }
2511
2371
      my_error(ER_FOREIGN_DUPLICATE_KEY, MYF(0), table_share->table_name.str,
2512
2372
        str.c_ptr(), key_nr+1);
2513
 
      DBUG_VOID_RETURN;
 
2373
      return;
2514
2374
    }
2515
2375
    textno= ER_DUP_KEY;
2516
2376
    break;
2572
2432
    String str;
2573
2433
    get_error_message(error, &str);
2574
2434
    my_error(ER_ROW_IS_REFERENCED_2, MYF(0), str.c_ptr_safe());
2575
 
    DBUG_VOID_RETURN;
 
2435
    return;
2576
2436
  }
2577
2437
  case HA_ERR_NO_REFERENCED_ROW:
2578
2438
  {
2579
2439
    String str;
2580
2440
    get_error_message(error, &str);
2581
2441
    my_error(ER_NO_REFERENCED_ROW_2, MYF(0), str.c_ptr_safe());
2582
 
    DBUG_VOID_RETURN;
 
2442
    return;
2583
2443
  }
2584
2444
  case HA_ERR_TABLE_DEF_CHANGED:
2585
2445
    textno=ER_TABLE_DEF_CHANGED;
2587
2447
  case HA_ERR_NO_SUCH_TABLE:
2588
2448
    my_error(ER_NO_SUCH_TABLE, MYF(0), table_share->db.str,
2589
2449
             table_share->table_name.str);
2590
 
    DBUG_VOID_RETURN;
 
2450
    return;
2591
2451
  case HA_ERR_RBR_LOGGING_FAILED:
2592
2452
    textno= ER_BINLOG_ROW_LOGGING_FAILED;
2593
2453
    break;
2598
2458
    if ((int) key_nr >= 0)
2599
2459
      ptr= table->key_info[key_nr].name;
2600
2460
    my_error(ER_DROP_INDEX_FK, MYF(0), ptr);
2601
 
    DBUG_VOID_RETURN;
 
2461
    return;
2602
2462
  }
2603
2463
  case HA_ERR_TABLE_NEEDS_UPGRADE:
2604
2464
    textno=ER_TABLE_NEEDS_UPGRADE;
2615
2475
  case HA_ERR_LOCK_OR_ACTIVE_TRANSACTION:
2616
2476
    my_message(ER_LOCK_OR_ACTIVE_TRANSACTION,
2617
2477
               ER(ER_LOCK_OR_ACTIVE_TRANSACTION), MYF(0));
2618
 
    DBUG_VOID_RETURN;
 
2478
    return;
2619
2479
    break;
2620
2480
  default:
2621
2481
    {
2634
2494
      }
2635
2495
      else
2636
2496
        my_error(ER_GET_ERRNO,errflag,error);
2637
 
      DBUG_VOID_RETURN;
 
2497
      return;
2638
2498
    }
2639
2499
  }
2640
2500
  my_error(textno, errflag, table_share->table_name.str, error);
2641
 
  DBUG_VOID_RETURN;
 
2501
  return;
2642
2502
}
2643
2503
 
2644
2504
 
2702
2562
  char path[FN_REFLEN];
2703
2563
  File file;
2704
2564
  bool result= true;
2705
 
  DBUG_ENTER("update_frm_version");
2706
2565
 
2707
2566
  /*
2708
2567
    No need to update frm version in case table was created or checked
2711
2570
    temporary tables.
2712
2571
  */
2713
2572
  if (table->s->mysql_version == MYSQL_VERSION_ID)
2714
 
    DBUG_RETURN(0);
 
2573
    return(0);
2715
2574
 
2716
2575
  strxmov(path, table->s->normalized_path.str, reg_ext, NullS);
2717
2576
 
2739
2598
err:
2740
2599
  if (file >= 0)
2741
2600
    VOID(my_close(file,MYF(MY_WME)));
2742
 
  DBUG_RETURN(result);
 
2601
  return(result);
2743
2602
}
2744
2603
 
2745
2604
 
2750
2609
*/
2751
2610
uint handler::get_dup_key(int error)
2752
2611
{
2753
 
  DBUG_ENTER("handler::get_dup_key");
2754
2612
  table->file->errkey  = (uint) -1;
2755
2613
  if (error == HA_ERR_FOUND_DUPP_KEY || error == HA_ERR_FOREIGN_DUPLICATE_KEY ||
2756
2614
      error == HA_ERR_FOUND_DUPP_UNIQUE ||
2757
2615
      error == HA_ERR_DROP_INDEX_FK)
2758
2616
    info(HA_STATUS_ERRKEY | HA_STATUS_NO_LOCK);
2759
 
  DBUG_RETURN(table->file->errkey);
 
2617
  return(table->file->errkey);
2760
2618
}
2761
2619
 
2762
2620
 
2878
2736
  */
2879
2737
  if (ha_info->is_started())
2880
2738
  {
2881
 
    DBUG_ASSERT(has_transactions());
 
2739
    assert(has_transactions());
2882
2740
    /*
2883
2741
      table_share can be NULL in ha_delete_table(). See implementation
2884
2742
      of standalone function ha_delete_table() in sql_base.cc.
3147
3005
int ha_enable_transaction(THD *thd, bool on)
3148
3006
{
3149
3007
  int error=0;
3150
 
  DBUG_ENTER("ha_enable_transaction");
3151
 
  DBUG_PRINT("enter", ("on: %d", (int) on));
3152
3008
 
3153
3009
  if ((thd->transaction.on= on))
3154
3010
  {
3161
3017
    if (!(error= ha_commit_trans(thd, 0)))
3162
3018
      error= end_trans(thd, COMMIT);
3163
3019
  }
3164
 
  DBUG_RETURN(error);
 
3020
  return(error);
3165
3021
}
3166
3022
 
3167
3023
int handler::index_next_same(uchar *buf, const uchar *key, uint keylen)
3168
3024
{
3169
3025
  int error;
3170
 
  DBUG_ENTER("index_next_same");
3171
3026
  if (!(error=index_next(buf)))
3172
3027
  {
3173
3028
    my_ptrdiff_t ptrdiff= buf - table->record[0];
3193
3048
      key_part_end= key_part + key_info->key_parts;
3194
3049
      for (; key_part < key_part_end; key_part++)
3195
3050
      {
3196
 
        DBUG_ASSERT(key_part->field);
 
3051
        assert(key_part->field);
3197
3052
        key_part->field->move_field_offset(ptrdiff);
3198
3053
      }
3199
3054
    }
3212
3067
        key_part->field->move_field_offset(-ptrdiff);
3213
3068
    }
3214
3069
  }
3215
 
  DBUG_RETURN(error);
 
3070
  return(error);
3216
3071
}
3217
3072
 
3218
3073
 
3238
3093
  char name_buff[FN_REFLEN];
3239
3094
  const char *name;
3240
3095
  TABLE_SHARE share;
3241
 
  DBUG_ENTER("ha_create_table");
3242
3096
  
3243
3097
  init_tmp_table_share(thd, &share, db, 0, table_name, path);
3244
3098
  if (open_table_def(thd, &share, 0) ||
3260
3114
  }
3261
3115
err:
3262
3116
  free_table_share(&share);
3263
 
  DBUG_RETURN(error != 0);
 
3117
  return(error != 0);
3264
3118
}
3265
3119
 
3266
3120
/**
3285
3139
  HA_CREATE_INFO create_info;
3286
3140
  TABLE table;
3287
3141
  TABLE_SHARE share;
3288
 
  DBUG_ENTER("ha_create_table_from_engine");
3289
 
  DBUG_PRINT("enter", ("name '%s'.'%s'", db, name));
3290
3142
 
3291
3143
  bzero((uchar*) &create_info,sizeof(create_info));
3292
3144
  if ((error= ha_discover(thd, db, name, &frmblob, &frmlen)))
3293
3145
  {
3294
3146
    /* Table could not be discovered and thus not created */
3295
 
    DBUG_RETURN(error);
 
3147
    return(error);
3296
3148
  }
3297
3149
 
3298
3150
  /*
3305
3157
  error= writefrm(path, frmblob, frmlen);
3306
3158
  my_free(frmblob, MYF(0));
3307
3159
  if (error)
3308
 
    DBUG_RETURN(2);
 
3160
    return(2);
3309
3161
 
3310
3162
  init_tmp_table_share(thd, &share, db, 0, name, path);
3311
3163
  if (open_table_def(thd, &share, 0))
3312
3164
  {
3313
 
    DBUG_RETURN(3);
 
3165
    return(3);
3314
3166
  }
3315
3167
  if (open_table_from_share(thd, &share, "" ,0, 0, 0, &table, OTM_OPEN))
3316
3168
  {
3317
3169
    free_table_share(&share);
3318
 
    DBUG_RETURN(3);
 
3170
    return(3);
3319
3171
  }
3320
3172
 
3321
3173
  update_create_info_from_table(&create_info, &table);
3325
3177
  error=table.file->ha_create(path, &table, &create_info);
3326
3178
  VOID(closefrm(&table, 1));
3327
3179
 
3328
 
  DBUG_RETURN(error != 0);
 
3180
  return(error != 0);
3329
3181
}
3330
3182
 
3331
3183
void st_ha_check_opt::init()
3351
3203
int ha_init_key_cache(const char *name __attribute__((__unused__)),
3352
3204
                      KEY_CACHE *key_cache)
3353
3205
{
3354
 
  DBUG_ENTER("ha_init_key_cache");
3355
 
 
3356
3206
  if (!key_cache->key_cache_inited)
3357
3207
  {
3358
3208
    pthread_mutex_lock(&LOCK_global_system_variables);
3361
3211
    uint division_limit= key_cache->param_division_limit;
3362
3212
    uint age_threshold=  key_cache->param_age_threshold;
3363
3213
    pthread_mutex_unlock(&LOCK_global_system_variables);
3364
 
    DBUG_RETURN(!init_key_cache(key_cache,
 
3214
    return(!init_key_cache(key_cache,
3365
3215
                                tmp_block_size,
3366
3216
                                tmp_buff_size,
3367
3217
                                division_limit, age_threshold));
3368
3218
  }
3369
 
  DBUG_RETURN(0);
 
3219
  return(0);
3370
3220
}
3371
3221
 
3372
3222
 
3375
3225
*/
3376
3226
int ha_resize_key_cache(KEY_CACHE *key_cache)
3377
3227
{
3378
 
  DBUG_ENTER("ha_resize_key_cache");
3379
 
 
3380
3228
  if (key_cache->key_cache_inited)
3381
3229
  {
3382
3230
    pthread_mutex_lock(&LOCK_global_system_variables);
3385
3233
    uint division_limit= key_cache->param_division_limit;
3386
3234
    uint age_threshold=  key_cache->param_age_threshold;
3387
3235
    pthread_mutex_unlock(&LOCK_global_system_variables);
3388
 
    DBUG_RETURN(!resize_key_cache(key_cache, tmp_block_size,
 
3236
    return(!resize_key_cache(key_cache, tmp_block_size,
3389
3237
                                  tmp_buff_size,
3390
3238
                                  division_limit, age_threshold));
3391
3239
  }
3392
 
  DBUG_RETURN(0);
 
3240
  return(0);
3393
3241
}
3394
3242
 
3395
3243
 
3465
3313
                uchar **frmblob, size_t *frmlen)
3466
3314
{
3467
3315
  int error= -1; // Table does not exist in any handler
3468
 
  DBUG_ENTER("ha_discover");
3469
 
  DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
3470
3316
  st_discover_args args= {db, name, frmblob, frmlen};
3471
3317
 
3472
3318
  if (is_prefix(name,tmp_file_prefix)) /* skip temporary tables */
3473
 
    DBUG_RETURN(error);
 
3319
    return(error);
3474
3320
 
3475
3321
  if (plugin_foreach(thd, discover_handlerton,
3476
3322
                 MYSQL_STORAGE_ENGINE_PLUGIN, &args))
3478
3324
 
3479
3325
  if (!error)
3480
3326
    status_var_increment(thd->status_var.ha_discover_count);
3481
 
  DBUG_RETURN(error);
 
3327
  return(error);
3482
3328
}
3483
3329
 
3484
3330
 
3532
3378
 
3533
3379
int ha_table_exists_in_engine(THD* thd, const char* db, const char* name)
3534
3380
{
3535
 
  DBUG_ENTER("ha_table_exists_in_engine");
3536
 
  DBUG_PRINT("enter", ("db: %s, name: %s", db, name));
3537
3381
  st_table_exists_in_engine_args args= {db, name, HA_ERR_NO_SUCH_TABLE};
3538
3382
  plugin_foreach(thd, table_exists_in_engine_handlerton,
3539
3383
                 MYSQL_STORAGE_ENGINE_PLUGIN, &args);
3540
 
  DBUG_PRINT("exit", ("error: %d", args.err));
3541
 
  DBUG_RETURN(args.err);
 
3384
  return(args.err);
3542
3385
}
3543
3386
 
3544
3387
/**
3765
3608
                               uint n_ranges, uint mode,
3766
3609
                               HANDLER_BUFFER *buf __attribute__((__unused__)))
3767
3610
{
3768
 
  DBUG_ENTER("handler::multi_range_read_init");
3769
3611
  mrr_iter= seq_funcs->init(seq_init_param, n_ranges, mode);
3770
3612
  mrr_funcs= *seq_funcs;
3771
3613
  mrr_is_output_sorted= test(mode & HA_MRR_SORTED);
3772
3614
  mrr_have_range= false;
3773
 
  DBUG_RETURN(0);
 
3615
  return(0);
3774
3616
}
3775
3617
 
3776
3618
 
3791
3633
{
3792
3634
  int result= 0;
3793
3635
  int range_res;
3794
 
  DBUG_ENTER("handler::multi_range_read_next");
3795
3636
 
3796
3637
  if (!mrr_have_range)
3797
3638
  {
3838
3679
  while ((result == HA_ERR_END_OF_FILE) && !range_res);
3839
3680
 
3840
3681
  *range_info= mrr_cur_range.ptr;
3841
 
  DBUG_PRINT("exit",("handler::multi_range_read_next result %d", result));
3842
 
  DBUG_RETURN(result);
 
3682
  return(result);
3843
3683
}
3844
3684
 
3845
3685
 
3873
3713
  uint keyno;
3874
3714
  Item *pushed_cond= NULL;
3875
3715
  handler *new_h2;
3876
 
  DBUG_ENTER("DsMrr_impl::dsmrr_init");
3877
3716
  keyno= h->active_index;
3878
 
  DBUG_ASSERT(h2 == NULL);
 
3717
  assert(h2 == NULL);
3879
3718
  if (mode & HA_MRR_USE_DEFAULT_IMPL || mode & HA_MRR_SORTED)
3880
3719
  {
3881
3720
    use_default_impl= true;
3882
 
    DBUG_RETURN(h->handler::multi_range_read_init(seq_funcs, seq_init_param,
 
3721
    return(h->handler::multi_range_read_init(seq_funcs, seq_init_param,
3883
3722
                                                  n_ranges, mode, buf));
3884
3723
  }
3885
3724
  rowids_buf= buf->buffer;
3901
3740
      new_h2->ha_external_lock(thd, F_RDLCK))
3902
3741
  {
3903
3742
    delete new_h2;
3904
 
    DBUG_RETURN(1);
 
3743
    return(1);
3905
3744
  }
3906
3745
 
3907
3746
  if (keyno == h->pushed_idx_cond_keyno)
3937
3776
  if (h->ha_rnd_init(false))
3938
3777
    goto error;
3939
3778
  
3940
 
  DBUG_RETURN(0);
 
3779
  return(0);
3941
3780
error:
3942
3781
  h2->ha_index_or_rnd_end();
3943
3782
  h2->ha_external_lock(thd, F_UNLCK);
3944
3783
  h2->close();
3945
3784
  delete h2;
3946
 
  DBUG_RETURN(1);
 
3785
  return(1);
3947
3786
}
3948
3787
 
3949
3788
 
3950
3789
void DsMrr_impl::dsmrr_close()
3951
3790
{
3952
 
  DBUG_ENTER("DsMrr_impl::dsmrr_close");
3953
3791
  if (h2)
3954
3792
  {
3955
3793
    h2->ha_external_lock(current_thd, F_UNLCK);
3958
3796
    h2= NULL;
3959
3797
  }
3960
3798
  use_default_impl= true;
3961
 
  DBUG_VOID_RETURN;
 
3799
  return;
3962
3800
}
3963
3801
 
3964
3802
 
3989
3827
{
3990
3828
  char *range_info;
3991
3829
  int res;
3992
 
  DBUG_ENTER("DsMrr_impl::dsmrr_fill_buffer");
3993
3830
 
3994
3831
  rowids_buf_cur= rowids_buf;
3995
3832
  while ((rowids_buf_cur < rowids_buf_end) && 
4008
3845
  }
4009
3846
 
4010
3847
  if (res && res != HA_ERR_END_OF_FILE)
4011
 
    DBUG_RETURN(res); 
 
3848
    return(res); 
4012
3849
  dsmrr_eof= test(res == HA_ERR_END_OF_FILE);
4013
3850
 
4014
3851
  /* Sort the buffer contents by rowid */
4019
3856
            (void*)h);
4020
3857
  rowids_buf_last= rowids_buf_cur;
4021
3858
  rowids_buf_cur=  rowids_buf;
4022
 
  DBUG_RETURN(0);
 
3859
  return(0);
4023
3860
}
4024
3861
 
4025
3862
 
4081
3918
  /* Get cost/flags/mem_usage of default MRR implementation */
4082
3919
  res= h->handler::multi_range_read_info(keyno, n_ranges, rows, &def_bufsz,
4083
3920
                                         &def_flags, cost);
4084
 
  DBUG_ASSERT(!res);
 
3921
  assert(!res);
4085
3922
 
4086
3923
  if ((*flags & HA_MRR_USE_DEFAULT_IMPL) || 
4087
3924
      choose_mrr_impl(keyno, rows, &def_flags, &def_bufsz, cost))
4088
3925
  {
4089
3926
    /* Default implementation is choosen */
4090
 
    DBUG_PRINT("info", ("Default MRR implementation choosen"));
4091
3927
    *flags= def_flags;
4092
3928
    *bufsz= def_bufsz;
4093
3929
  }
4094
 
  else
4095
 
  {
4096
 
    DBUG_PRINT("info", ("DS-MRR implementation choosen"));
4097
 
  }
4098
3930
  return 0;
4099
3931
}
4100
3932
 
4128
3960
  if ((*flags & HA_MRR_USE_DEFAULT_IMPL) ||
4129
3961
      choose_mrr_impl(keyno, rows, flags, bufsz, cost))
4130
3962
  {
4131
 
    DBUG_PRINT("info", ("Default MRR implementation choosen"));
4132
3963
    *flags= def_flags;
4133
3964
    *bufsz= def_bufsz;
4134
3965
  }
4135
3966
  else
4136
3967
  {
4137
3968
    *flags &= ~HA_MRR_USE_DEFAULT_IMPL;
4138
 
    DBUG_PRINT("info", ("DS-MRR implementation choosen"));
4139
3969
  }
4140
3970
  return rows;
4141
3971
}
4395
4225
void get_sweep_read_cost(TABLE *table, ha_rows nrows, bool interrupted, 
4396
4226
                         COST_VECT *cost)
4397
4227
{
4398
 
  DBUG_ENTER("get_sweep_read_cost");
4399
 
 
4400
4228
  cost->zero();
4401
4229
  if (table->file->primary_key_is_clustered())
4402
4230
  {
4412
4240
    if (busy_blocks < 1.0)
4413
4241
      busy_blocks= 1.0;
4414
4242
 
4415
 
    DBUG_PRINT("info",("sweep: nblocks=%g, busy_blocks=%g", n_blocks,
4416
 
                       busy_blocks));
4417
4243
    cost->io_count= busy_blocks;
4418
4244
 
4419
4245
    if (!interrupted)
4423
4249
                          DISK_SEEK_PROP_COST*n_blocks/busy_blocks);
4424
4250
    }
4425
4251
  }
4426
 
  DBUG_PRINT("info",("returning cost=%g", cost->total_cost()));
4427
 
  DBUG_VOID_RETURN;
 
4252
  return;
4428
4253
}
4429
4254
 
4430
4255
 
4456
4281
                              bool sorted  __attribute__((__unused__)))
4457
4282
{
4458
4283
  int result;
4459
 
  DBUG_ENTER("handler::read_range_first");
4460
4284
 
4461
4285
  eq_range= eq_range_arg;
4462
4286
  end_range= 0;
4477
4301
                           start_key->keypart_map,
4478
4302
                           start_key->flag);
4479
4303
  if (result)
4480
 
    DBUG_RETURN((result == HA_ERR_KEY_NOT_FOUND) 
 
4304
    return((result == HA_ERR_KEY_NOT_FOUND) 
4481
4305
                ? HA_ERR_END_OF_FILE
4482
4306
                : result);
4483
4307
 
4484
 
  DBUG_RETURN (compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
 
4308
  return (compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
4485
4309
}
4486
4310
 
4487
4311
 
4501
4325
int handler::read_range_next()
4502
4326
{
4503
4327
  int result;
4504
 
  DBUG_ENTER("handler::read_range_next");
4505
4328
 
4506
4329
  if (eq_range)
4507
4330
  {
4508
4331
    /* We trust that index_next_same always gives a row in range */
4509
 
    DBUG_RETURN(index_next_same(table->record[0],
 
4332
    return(index_next_same(table->record[0],
4510
4333
                                end_range->key,
4511
4334
                                end_range->length));
4512
4335
  }
4513
4336
  result= index_next(table->record[0]);
4514
4337
  if (result)
4515
 
    DBUG_RETURN(result);
4516
 
  DBUG_RETURN(compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
 
4338
    return(result);
 
4339
  return(compare_key(end_range) <= 0 ? 0 : HA_ERR_END_OF_FILE);
4517
4340
}
4518
4341
 
4519
4342
 
4631
4454
                                       (found_exts.elements+1),
4632
4455
                                       MYF(MY_WME | MY_FAE));
4633
4456
 
4634
 
    DBUG_ASSERT(ext != 0);
 
4457
    assert(ext != 0);
4635
4458
    known_extensions.count= found_exts.elements;
4636
4459
    known_extensions.type_names= ext;
4637
4460
 
4702
4525
    table->s->cached_row_logging_check= check;
4703
4526
  }
4704
4527
 
4705
 
  DBUG_ASSERT(table->s->cached_row_logging_check == 0 ||
 
4528
  assert(table->s->cached_row_logging_check == 0 ||
4706
4529
              table->s->cached_row_logging_check == 1);
4707
4530
 
4708
4531
  return (thd->current_stmt_binlog_row_based &&
4733
4556
 
4734
4557
static int write_locked_table_maps(THD *thd)
4735
4558
{
4736
 
  DBUG_ENTER("write_locked_table_maps");
4737
 
  DBUG_PRINT("enter", ("thd: 0x%lx  thd->lock: 0x%lx  thd->locked_tables: 0x%lx  "
4738
 
                       "thd->extra_lock: 0x%lx",
4739
 
                       (long) thd, (long) thd->lock,
4740
 
                       (long) thd->locked_tables, (long) thd->extra_lock));
4741
 
 
4742
4559
  if (thd->get_binlog_table_maps() == 0)
4743
4560
  {
4744
4561
    MYSQL_LOCK *locks[3];
4757
4574
           ++table_ptr)
4758
4575
      {
4759
4576
        TABLE *const table= *table_ptr;
4760
 
        DBUG_PRINT("info", ("Checking table %s", table->s->table_name.str));
4761
4577
        if (table->current_lock == F_WRLCK &&
4762
4578
            check_table_binlog_row_based(thd, table))
4763
4579
        {
4768
4584
            roll back the transaction.
4769
4585
          */
4770
4586
          if (unlikely(error))
4771
 
            DBUG_RETURN(1);
 
4587
            return(1);
4772
4588
        }
4773
4589
      }
4774
4590
    }
4775
4591
  }
4776
 
  DBUG_RETURN(0);
 
4592
  return(0);
4777
4593
}
4778
4594
 
4779
4595
 
4791
4607
 
4792
4608
  if (check_table_binlog_row_based(thd, table))
4793
4609
  {
4794
 
    DBUG_DUMP("read_set 10", (uchar*) table->read_set->bitmap,
4795
 
              (table->s->fields + 7) / 8);
4796
4610
    /*
4797
4611
      If there are no table maps written to the binary log, this is
4798
4612
      the first row handled in this statement. In that case, we need
4809
4623
 
4810
4624
int handler::ha_external_lock(THD *thd, int lock_type)
4811
4625
{
4812
 
  DBUG_ENTER("handler::ha_external_lock");
4813
4626
  /*
4814
4627
    Whether this is lock or unlock, this should be true, and is to verify that
4815
4628
    if get_auto_increment() was called (thus may have reserved intervals or
4816
4629
    taken a table lock), ha_release_auto_increment() was too.
4817
4630
  */
4818
 
  DBUG_ASSERT(next_insert_id == 0);
 
4631
  assert(next_insert_id == 0);
4819
4632
 
4820
4633
  /*
4821
4634
    We cache the table flags if the locking succeeded. Otherwise, we
4826
4639
  int error= external_lock(thd, lock_type);
4827
4640
  if (error == 0)
4828
4641
    cached_table_flags= table_flags();
4829
 
  DBUG_RETURN(error);
 
4642
  return(error);
4830
4643
}
4831
4644
 
4832
4645
 
4835
4648
*/
4836
4649
int handler::ha_reset()
4837
4650
{
4838
 
  DBUG_ENTER("ha_reset");
4839
4651
  /* Check that we have called all proper deallocation functions */
4840
 
  DBUG_ASSERT((uchar*) table->def_read_set.bitmap +
 
4652
  assert((uchar*) table->def_read_set.bitmap +
4841
4653
              table->s->column_bitmap_size ==
4842
4654
              (uchar*) table->def_write_set.bitmap);
4843
 
  DBUG_ASSERT(bitmap_is_set_all(&table->s->all_set));
4844
 
  DBUG_ASSERT(table->key_read == 0);
 
4655
  assert(bitmap_is_set_all(&table->s->all_set));
 
4656
  assert(table->key_read == 0);
4845
4657
  /* ensure that ha_index_end / ha_rnd_end has been called */
4846
 
  DBUG_ASSERT(inited == NONE);
 
4658
  assert(inited == NONE);
4847
4659
  /* Free cache used by filesort */
4848
4660
  free_io_cache(table);
4849
4661
  /* reset the bitmaps to point to defaults */
4850
4662
  table->default_column_bitmaps();
4851
 
  DBUG_RETURN(reset());
 
4663
  return(reset());
4852
4664
}
4853
4665
 
4854
4666
 
4856
4668
{
4857
4669
  int error;
4858
4670
  Log_func *log_func= Write_rows_log_event::binlog_row_logging_function;
4859
 
  DBUG_ENTER("handler::ha_write_row");
4860
4671
  MYSQL_INSERT_ROW_START();
4861
4672
 
4862
4673
  mark_trx_read_write();
4863
4674
 
4864
4675
  if (unlikely(error= write_row(buf)))
4865
 
    DBUG_RETURN(error);
 
4676
    return(error);
4866
4677
  if (unlikely(error= binlog_log_row(table, 0, buf, log_func)))
4867
 
    DBUG_RETURN(error); /* purecov: inspected */
 
4678
    return(error); /* purecov: inspected */
4868
4679
  MYSQL_INSERT_ROW_END();
4869
 
  DBUG_RETURN(0);
 
4680
  return(0);
4870
4681
}
4871
4682
 
4872
4683
 
4879
4690
    Some storage engines require that the new record is in record[0]
4880
4691
    (and the old record is in record[1]).
4881
4692
   */
4882
 
  DBUG_ASSERT(new_data == table->record[0]);
 
4693
  assert(new_data == table->record[0]);
4883
4694
 
4884
4695
  mark_trx_read_write();
4885
4696