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