~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/haildb/haildb_engine.cc

  • Committer: Brian Aker
  • Date: 2011-01-12 06:45:23 UTC
  • mto: (2073.1.4 catalogs)
  • mto: This revision was merged to the branch mainline in revision 2080.
  • Revision ID: brian@tangent.org-20110112064523-rqhptaqbph22qmj1
RemoveĀ customĀ error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
***********************************************************************/
72
72
 
73
73
 
74
 
#include <config.h>
 
74
#include "config.h"
75
75
#include <drizzled/table.h>
76
76
#include <drizzled/error.h>
77
 
#include <drizzled/internal/my_pthread.h>
 
77
#include "drizzled/internal/my_pthread.h"
78
78
#include <drizzled/plugin/transactional_storage_engine.h>
79
79
#include <drizzled/plugin/error_message.h>
80
80
 
88
88
#include <map>
89
89
#include <fstream>
90
90
#include <drizzled/message/table.pb.h>
91
 
#include <drizzled/internal/m_string.h>
 
91
#include "drizzled/internal/m_string.h"
92
92
 
93
 
#include <drizzled/global_charset_info.h>
 
93
#include "drizzled/global_charset_info.h"
94
94
 
95
95
#include "haildb_datadict_dump_func.h"
96
96
#include "config_table_function.h"
101
101
#include "haildb_engine.h"
102
102
 
103
103
#include <drizzled/field.h>
104
 
#include <drizzled/field/blob.h>
105
 
#include <drizzled/field/enum.h>
 
104
#include "drizzled/field/blob.h"
 
105
#include "drizzled/field/enum.h"
106
106
#include <drizzled/session.h>
 
107
#include <boost/program_options.hpp>
107
108
#include <drizzled/module/option_map.h>
 
109
#include <iostream>
108
110
#include <drizzled/charset.h>
109
 
#include <drizzled/current_session.h>
110
 
 
111
 
#include <iostream>
112
111
 
113
112
namespace po= boost::program_options;
114
 
#include <boost/program_options.hpp>
115
113
#include <boost/algorithm/string.hpp>
116
114
 
117
115
using namespace std;
118
116
using namespace google;
119
117
using namespace drizzled;
120
118
 
121
 
int read_row_from_haildb(Session *session, unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot= NULL);
 
119
int read_row_from_haildb(unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot= NULL);
122
120
static void fill_ib_search_tpl_from_drizzle_key(ib_tpl_t search_tuple,
123
121
                                                const drizzled::KeyInfo *key_info,
124
122
                                                const unsigned char *key_ptr,
167
165
 
168
166
  int doCreateTable(Session&,
169
167
                    Table& table_arg,
170
 
                    const drizzled::identifier::Table &identifier,
 
168
                    const drizzled::TableIdentifier &identifier,
171
169
                    drizzled::message::Table& proto);
172
170
 
173
 
  int doDropTable(Session&, const identifier::Table &identifier);
 
171
  int doDropTable(Session&, const TableIdentifier &identifier);
174
172
 
175
173
  int doRenameTable(drizzled::Session&,
176
 
                    const drizzled::identifier::Table&,
177
 
                    const drizzled::identifier::Table&);
 
174
                    const drizzled::TableIdentifier&,
 
175
                    const drizzled::TableIdentifier&);
178
176
 
179
177
  int doGetTableDefinition(Session& session,
180
 
                           const identifier::Table &identifier,
 
178
                           const TableIdentifier &identifier,
181
179
                           drizzled::message::Table &table_proto);
182
180
 
183
 
  bool doDoesTableExist(Session&, const identifier::Table &identifier);
 
181
  bool doDoesTableExist(Session&, const TableIdentifier &identifier);
184
182
 
185
183
private:
186
 
  void getTableNamesInSchemaFromHailDB(const drizzled::identifier::Schema &schema,
 
184
  void getTableNamesInSchemaFromHailDB(const drizzled::SchemaIdentifier &schema,
187
185
                                       drizzled::plugin::TableNameList *set_of_names,
188
 
                                       drizzled::identifier::Table::vector *identifiers);
 
186
                                       drizzled::TableIdentifier::vector *identifiers);
189
187
 
190
188
public:
191
189
  void doGetTableIdentifiers(drizzled::CachedDirectory &,
192
 
                             const drizzled::identifier::Schema &schema,
193
 
                             drizzled::identifier::Table::vector &identifiers);
 
190
                             const drizzled::SchemaIdentifier &schema,
 
191
                             drizzled::TableIdentifier::vector &identifiers);
194
192
 
195
193
  /* The following defines can be increased if necessary */
196
194
  uint32_t max_supported_keys()          const { return 1000; }
241
239
/* This is a superset of the map from innobase plugin.
242
240
   Unlike innobase plugin we don't act on errors here, we just
243
241
   map error codes. */
244
 
static int ib_err_t_to_drizzle_error(Session* session, ib_err_t err)
 
242
static int ib_err_t_to_drizzle_error(ib_err_t err)
245
243
{
246
244
  switch (err)
247
245
  {
271
269
    return HA_ERR_NO_ACTIVE_RECORD;
272
270
 
273
271
  case DB_DEADLOCK:
274
 
    /* HailDB will roll back a transaction itself due to DB_DEADLOCK.
275
 
       This means we have to tell Drizzle about it */
276
 
    session->markTransactionForRollback(true);
277
272
    return HA_ERR_LOCK_DEADLOCK;
278
273
 
279
274
  case DB_LOCK_WAIT_TIMEOUT:
280
 
    session->markTransactionForRollback(false);
281
275
    return HA_ERR_LOCK_WAIT_TIMEOUT;
282
276
 
283
277
  case DB_NO_REFERENCED_ROW:
356
350
  (void)options;
357
351
 
358
352
  transaction= get_trx(session);
359
 
  isolation_level= tx_isolation_to_ib_trx_level(session->getTxIsolation());
 
353
  isolation_level= tx_isolation_to_ib_trx_level((enum_tx_isolation)session_tx_isolation(session));
360
354
  *transaction= ib_trx_begin(isolation_level);
361
355
 
362
356
  return *transaction == NULL;
393
387
  err= ib_savepoint_rollback(*transaction, savepoint.getName().c_str(),
394
388
                             savepoint.getName().length());
395
389
 
396
 
  return ib_err_t_to_drizzle_error(session, err);
 
390
  return ib_err_t_to_drizzle_error(err);
397
391
}
398
392
 
399
393
int HailDBEngine::doReleaseSavepoint(Session* session,
405
399
  err= ib_savepoint_release(*transaction, savepoint.getName().c_str(),
406
400
                            savepoint.getName().length());
407
401
  if (err != DB_SUCCESS)
408
 
    return ib_err_t_to_drizzle_error(session, err);
 
402
    return ib_err_t_to_drizzle_error(err);
409
403
 
410
404
  return 0;
411
405
}
415
409
  ib_err_t err;
416
410
  ib_trx_t *transaction= get_trx(session);
417
411
 
418
 
  if (all)
 
412
  if (all || (!session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
419
413
  {
420
414
    err= ib_trx_commit(*transaction);
421
415
 
422
416
    if (err != DB_SUCCESS)
423
 
      return ib_err_t_to_drizzle_error(session, err);
 
417
      return ib_err_t_to_drizzle_error(err);
424
418
 
425
419
    *transaction= NULL;
426
420
  }
433
427
  ib_err_t err;
434
428
  ib_trx_t *transaction= get_trx(session);
435
429
 
436
 
  if (all)
 
430
  if (all || !session_test_options(session, OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
437
431
  {
438
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
439
 
      err= ib_trx_release(*transaction);
440
 
    else
441
 
      err= ib_trx_rollback(*transaction);
 
432
    err= ib_trx_rollback(*transaction);
442
433
 
443
434
    if (err != DB_SUCCESS)
444
 
      return ib_err_t_to_drizzle_error(session, err);
 
435
      return ib_err_t_to_drizzle_error(err);
445
436
 
446
437
    *transaction= NULL;
447
438
  }
448
439
  else
449
440
  {
450
 
    if (ib_trx_state(*transaction) == IB_TRX_NOT_STARTED)
451
 
      return 0;
452
 
 
453
441
    err= ib_savepoint_rollback(*transaction, statement_savepoint_name.c_str(),
454
442
                               statement_savepoint_name.length());
455
443
    if (err != DB_SUCCESS)
456
 
      return ib_err_t_to_drizzle_error(session, err);
 
444
      return ib_err_t_to_drizzle_error(err);
457
445
  }
458
446
 
459
447
  return 0;
538
526
  doEndIndexScan();
539
527
  (void) extra(HA_EXTRA_NO_KEYREAD);
540
528
 
541
 
  if (getTable()->getShare()->getTableMessage()->options().auto_increment_value() > nr)
542
 
    nr= getTable()->getShare()->getTableMessage()->options().auto_increment_value();
 
529
  if (getTable()->getShare()->getTableProto()->options().auto_increment_value() > nr)
 
530
    nr= getTable()->getShare()->getTableProto()->options().auto_increment_value();
543
531
 
544
532
  return nr;
545
533
}
652
640
 
653
641
  /* the below is adapted from ha_innodb.cc */
654
642
 
655
 
  const uint32_t sql_command = session->getSqlCommand();
 
643
  const uint32_t sql_command = session_sql_command(session);
656
644
 
657
645
  if (sql_command == SQLCOM_DROP_TABLE) {
658
646
 
683
671
    unexpected if an obsolete consistent read view would be
684
672
    used. */
685
673
 
686
 
    enum_tx_isolation isolation_level= session->getTxIsolation();
 
674
    enum_tx_isolation isolation_level= session_tx_isolation(session);
687
675
 
688
676
    if (isolation_level != ISO_SERIALIZABLE
689
677
        && (lock_type == TL_READ || lock_type == TL_READ_NO_INSERT)
726
714
 
727
715
    if ((lock_type >= TL_WRITE_CONCURRENT_INSERT
728
716
         && lock_type <= TL_WRITE)
729
 
        && ! session->doing_tablespace_operation()
 
717
        && !session_tablespace_op(session)
730
718
        && sql_command != SQLCOM_TRUNCATE
731
719
        && sql_command != SQLCOM_CREATE_TABLE) {
732
720
 
803
791
  return &name[l];
804
792
}
805
793
 
806
 
static void TableIdentifier_to_haildb_name(const identifier::Table &identifier, std::string *str)
 
794
static void TableIdentifier_to_haildb_name(const TableIdentifier &identifier, std::string *str)
807
795
{
808
796
  str->assign(table_path_to_haildb_name(identifier.getPath().c_str()));
809
797
}
837
825
  ib_id_t idx_id;
838
826
 
839
827
  if (err != DB_SUCCESS)
840
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
828
    return ib_err_t_to_drizzle_error(err);
841
829
 
842
830
  err= ib_cursor_open_table_using_id(table_id, NULL, &cursor);
843
831
  cursor_is_sec_index= false;
844
832
 
845
833
  if (err != DB_SUCCESS)
846
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
834
    return ib_err_t_to_drizzle_error(err);
847
835
 
848
836
  err= ib_index_get_id(haildb_table_name, "HIDDEN_PRIMARY", &idx_id);
849
837
 
874
862
{
875
863
  ib_err_t err= ib_cursor_close(cursor);
876
864
  if (err != DB_SUCCESS)
877
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
865
    return ib_err_t_to_drizzle_error(err);
878
866
 
879
867
  free_share();
880
868
 
1038
1026
 
1039
1027
int HailDBEngine::doCreateTable(Session &session,
1040
1028
                                        Table& table_obj,
1041
 
                                        const drizzled::identifier::Table &identifier,
 
1029
                                        const drizzled::TableIdentifier &identifier,
1042
1030
                                        drizzled::message::Table& table_message)
1043
1031
{
1044
1032
  ib_tbl_sch_t haildb_table_schema= NULL;
1082
1070
                        ER_CANT_CREATE_TABLE,
1083
1071
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1084
1072
                        haildb_table_name.c_str(), haildb_err, ib_strerror(haildb_err));
1085
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1073
    return ib_err_t_to_drizzle_error(haildb_err);
1086
1074
  }
1087
1075
 
1088
1076
  for (int colnr= 0; colnr < table_message.field_size() ; colnr++)
1103
1091
                            " HailDB Error %d (%s)\n"),
1104
1092
                          field.name().c_str(), haildb_table_name.c_str(),
1105
1093
                          haildb_err, ib_strerror(haildb_err));
1106
 
      return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1094
      return ib_err_t_to_drizzle_error(haildb_err);
1107
1095
    }
1108
1096
    if (field_err != 0)
1109
1097
      return field_err;
1251
1239
                        _("Cannot create table %s. HailDB Error %d (%s)\n"),
1252
1240
                        haildb_table_name.c_str(),
1253
1241
                        haildb_err, ib_strerror(haildb_err));
1254
 
    return ib_err_t_to_drizzle_error(&session, haildb_err);
 
1242
    return ib_err_t_to_drizzle_error(haildb_err);
1255
1243
  }
1256
1244
 
1257
1245
  return 0;
1294
1282
}
1295
1283
 
1296
1284
int HailDBEngine::doDropTable(Session &session,
1297
 
                                      const identifier::Table &identifier)
 
1285
                                      const TableIdentifier &identifier)
1298
1286
{
1299
1287
  ib_trx_t haildb_schema_transaction;
1300
1288
  ib_err_t haildb_err;
1376
1364
  return 0;
1377
1365
}
1378
1366
 
1379
 
static ib_err_t rename_table_message(ib_trx_t transaction, const identifier::Table &from_identifier, const identifier::Table &to_identifier)
 
1367
static ib_err_t rename_table_message(ib_trx_t transaction, const TableIdentifier &from_identifier, const TableIdentifier &to_identifier)
1380
1368
{
1381
1369
  ib_crsr_t cursor;
1382
1370
  ib_tpl_t search_tuple;
1467
1455
}
1468
1456
 
1469
1457
int HailDBEngine::doRenameTable(drizzled::Session &session,
1470
 
                                        const drizzled::identifier::Table &from,
1471
 
                                        const drizzled::identifier::Table &to)
 
1458
                                        const drizzled::TableIdentifier &from,
 
1459
                                        const drizzled::TableIdentifier &to)
1472
1460
{
1473
1461
  ib_trx_t haildb_schema_transaction;
1474
1462
  ib_err_t err;
1518
1506
  assert(rollback_err == DB_SUCCESS);
1519
1507
  rollback_err= ib_trx_rollback(haildb_schema_transaction);
1520
1508
  assert(rollback_err == DB_SUCCESS);
1521
 
  return ib_err_t_to_drizzle_error(&session, err);
 
1509
  return ib_err_t_to_drizzle_error(err);
1522
1510
}
1523
1511
 
1524
1512
void HailDBEngine::getTableNamesInSchemaFromHailDB(
1525
 
                                 const drizzled::identifier::Schema &schema,
 
1513
                                 const drizzled::SchemaIdentifier &schema,
1526
1514
                                 drizzled::plugin::TableNameList *set_of_names,
1527
 
                                 drizzled::identifier::Table::vector *identifiers)
 
1515
                                 drizzled::TableIdentifier::vector *identifiers)
1528
1516
{
1529
1517
  ib_trx_t   transaction;
1530
1518
  ib_crsr_t  cursor;
1554
1542
    {
1555
1543
      BOOST_FOREACH(std::string table_name, haildb_system_table_names)
1556
1544
      {
1557
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(),
 
1545
        identifiers->push_back(TableIdentifier(schema.getSchemaName(),
1558
1546
                                               table_name));
1559
1547
      }
1560
1548
    }
1597
1585
      if (set_of_names)
1598
1586
        set_of_names->insert(just_table_name);
1599
1587
      if (identifiers)
1600
 
        identifiers->push_back(identifier::Table(schema.getSchemaName(), just_table_name));
 
1588
        identifiers->push_back(TableIdentifier(schema.getSchemaName(), just_table_name));
1601
1589
    }
1602
1590
 
1603
1591
 
1616
1604
}
1617
1605
 
1618
1606
void HailDBEngine::doGetTableIdentifiers(drizzled::CachedDirectory &,
1619
 
                                                 const drizzled::identifier::Schema &schema,
1620
 
                                                 drizzled::identifier::Table::vector &identifiers)
 
1607
                                                 const drizzled::SchemaIdentifier &schema,
 
1608
                                                 drizzled::TableIdentifier::vector &identifiers)
1621
1609
{
1622
1610
  getTableNamesInSchemaFromHailDB(schema, NULL, &identifiers);
1623
1611
}
1742
1730
}
1743
1731
 
1744
1732
int HailDBEngine::doGetTableDefinition(Session &session,
1745
 
                                               const identifier::Table &identifier,
 
1733
                                               const TableIdentifier &identifier,
1746
1734
                                               drizzled::message::Table &table)
1747
1735
{
1748
1736
  ib_crsr_t haildb_cursor= NULL;
1771
1759
}
1772
1760
 
1773
1761
bool HailDBEngine::doDoesTableExist(Session &,
1774
 
                                    const identifier::Table& identifier)
 
1762
                                    const TableIdentifier& identifier)
1775
1763
{
1776
1764
  ib_crsr_t haildb_cursor;
1777
1765
  string haildb_table_name;
1913
1901
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
1914
1902
 
1915
1903
    if (err != DB_SUCCESS)
1916
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
1904
      return ib_err_t_to_drizzle_error(err);
1917
1905
 
1918
1906
    cursor_is_sec_index= false;
1919
1907
  }
1923
1911
  }
1924
1912
 
1925
1913
  err= ib_cursor_first(cursor);
1926
 
  if (current_session->getLex()->sql_command == SQLCOM_CREATE_TABLE
 
1914
  if (current_session->lex->sql_command == SQLCOM_CREATE_TABLE
1927
1915
      && err == DB_MISSING_HISTORY)
1928
1916
  {
1929
1917
    /* See https://bugs.launchpad.net/drizzle/+bug/556978
2022
2010
      ret= HA_ERR_FOUND_DUPP_KEY;
2023
2011
  }
2024
2012
  else if (err != DB_SUCCESS)
2025
 
    ret= ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2013
    ret= ib_err_t_to_drizzle_error(err);
2026
2014
 
2027
2015
  tuple= ib_tuple_clear(tuple);
2028
2016
  ib_tuple_delete(tuple);
2053
2041
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2054
2042
 
2055
2043
      if (err != DB_SUCCESS)
2056
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2044
        return ib_err_t_to_drizzle_error(err);
2057
2045
      cursor_is_sec_index= false;
2058
2046
    }
2059
2047
    else
2105
2093
 
2106
2094
  advance_cursor= true;
2107
2095
 
2108
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2096
  return ib_err_t_to_drizzle_error(err);
2109
2097
}
2110
2098
 
2111
2099
int HailDBCursor::doDeleteRecord(const unsigned char *)
2117
2105
 
2118
2106
  advance_cursor= true;
2119
2107
 
2120
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2108
  return ib_err_t_to_drizzle_error(err);
2121
2109
}
2122
2110
 
2123
2111
int HailDBCursor::delete_all_rows(void)
2126
2114
     so only support TRUNCATE and not DELETE FROM t;
2127
2115
     (this is what ha_innodb does)
2128
2116
  */
2129
 
  if (getTable()->in_use->getSqlCommand() != SQLCOM_TRUNCATE)
 
2117
  if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2130
2118
    return HA_ERR_WRONG_COMMAND;
2131
2119
 
2132
2120
  ib_id_t id;
2142
2130
    err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2143
2131
 
2144
2132
    if (err != DB_SUCCESS)
2145
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2133
      return ib_err_t_to_drizzle_error(err);
2146
2134
    cursor_is_sec_index= false;
2147
2135
  }
2148
2136
  else
2184
2172
  ib_schema_unlock(transaction);
2185
2173
  ib_err_t rollback_err= ib_trx_rollback(transaction);
2186
2174
  assert(rollback_err == DB_SUCCESS);
2187
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2175
  return ib_err_t_to_drizzle_error(err);
2188
2176
}
2189
2177
 
2190
2178
int HailDBCursor::doStartTableScan(bool)
2214
2202
  }
2215
2203
 
2216
2204
  if (err != DB_SUCCESS)
2217
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2205
    return ib_err_t_to_drizzle_error(err);
2218
2206
 
2219
2207
  err= ib_cursor_set_lock_mode(cursor, ib_lock_mode);
2220
2208
  assert(err == DB_SUCCESS); // FIXME
2226
2214
  {
2227
2215
    int reset_err= ib_cursor_reset(cursor);
2228
2216
    assert(reset_err == DB_SUCCESS);
2229
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2217
    return ib_err_t_to_drizzle_error(err);
2230
2218
  }
2231
2219
 
2232
2220
  advance_cursor= false;
2234
2222
  return(0);
2235
2223
}
2236
2224
 
2237
 
int read_row_from_haildb(Session *session, unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot)
 
2225
int read_row_from_haildb(unsigned char* buf, ib_crsr_t cursor, ib_tpl_t tuple, Table* table, bool has_hidden_primary_key, uint64_t *hidden_pkey, drizzled::memory::Root **blobroot)
2238
2226
{
2239
2227
  ib_err_t err;
2240
2228
  ptrdiff_t row_offset= buf - table->getInsertRecord();
2244
2232
  if (err == DB_RECORD_NOT_FOUND)
2245
2233
    return HA_ERR_END_OF_FILE;
2246
2234
  if (err != DB_SUCCESS)
2247
 
    return ib_err_t_to_drizzle_error(session, err);
 
2235
    return ib_err_t_to_drizzle_error(err);
2248
2236
 
2249
2237
  int colnr= 0;
2250
2238
 
2310
2298
    (**field).move_field_offset(-row_offset);
2311
2299
 
2312
2300
    if (err != DB_SUCCESS)
2313
 
      return ib_err_t_to_drizzle_error(session, err);
 
2301
      return ib_err_t_to_drizzle_error(err);
2314
2302
  }
2315
2303
 
2316
2304
  if (has_hidden_primary_key)
2318
2306
    err= ib_tuple_read_u64(tuple, colnr, hidden_pkey);
2319
2307
  }
2320
2308
 
2321
 
  return ib_err_t_to_drizzle_error(session, err);
 
2309
  return ib_err_t_to_drizzle_error(err);
2322
2310
}
2323
2311
 
2324
2312
int HailDBCursor::rnd_next(unsigned char *buf)
2330
2318
  {
2331
2319
    err= ib_cursor_next(cursor);
2332
2320
    if (err != DB_SUCCESS)
2333
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2321
      return ib_err_t_to_drizzle_error(err);
2334
2322
  }
2335
2323
 
2336
2324
  tuple= ib_tuple_clear(tuple);
2337
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2338
 
                            getTable(),
 
2325
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2339
2326
                            share->has_hidden_primary_key,
2340
2327
                            &hidden_autoinc_pkey_position);
2341
2328
 
2352
2339
  err= ib_cursor_reset(cursor);
2353
2340
  assert(err == DB_SUCCESS);
2354
2341
  in_table_scan= false;
2355
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2342
  return ib_err_t_to_drizzle_error(err);
2356
2343
}
2357
2344
 
2358
2345
int HailDBCursor::rnd_pos(unsigned char *buf, unsigned char *pos)
2367
2354
    err= ib_col_set_value(search_tuple, 0,
2368
2355
                          ((uint64_t*)(pos)), sizeof(uint64_t));
2369
2356
    if (err != DB_SUCCESS)
2370
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2357
      return ib_err_t_to_drizzle_error(err);
2371
2358
  }
2372
2359
  else
2373
2360
  {
2384
2371
 
2385
2372
  err= ib_cursor_moveto(cursor, search_tuple, IB_CUR_GE, &res);
2386
2373
  if (err != DB_SUCCESS)
2387
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2374
    return ib_err_t_to_drizzle_error(err);
2388
2375
 
2389
2376
  assert(res==0);
2390
2377
  if (res != 0)
2395
2382
  tuple= ib_tuple_clear(tuple);
2396
2383
 
2397
2384
  if (ret == 0)
2398
 
    ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2399
 
                              getTable(),
 
2385
    ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2400
2386
                              share->has_hidden_primary_key,
2401
2387
                              &hidden_autoinc_pkey_position);
2402
2388
 
2535
2521
 
2536
2522
  }
2537
2523
 
2538
 
  if (flag & HA_STATUS_CONST)
2539
 
  {
2540
 
    for (unsigned int i = 0; i < getTable()->getShare()->sizeKeys(); i++)
2541
 
    {
2542
 
      const char* index_name= getTable()->key_info[i].name;
2543
 
      uint64_t ncols;
2544
 
      int64_t *n_diff;
2545
 
      ha_rows rec_per_key;
2546
 
 
2547
 
      err= ib_get_index_stat_n_diff_key_vals(cursor, index_name,
2548
 
                                             &ncols, &n_diff);
2549
 
 
2550
 
      if (err != DB_SUCCESS)
2551
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2552
 
 
2553
 
      for (unsigned int j=0; j < getTable()->key_info[i].key_parts; j++)
2554
 
      {
2555
 
        if (n_diff[j+1] == 0)
2556
 
          rec_per_key= stats.records;
2557
 
        else
2558
 
          rec_per_key= stats.records / n_diff[j+1];
2559
 
 
2560
 
        /* We import this heuristic from ha_innodb, which says
2561
 
           that MySQL favours table scans too much over index searches,
2562
 
           so we pretend our index selectivity is 2 times better. */
2563
 
 
2564
 
        rec_per_key= rec_per_key / 2;
2565
 
 
2566
 
        if (rec_per_key == 0)
2567
 
          rec_per_key= 1;
2568
 
 
2569
 
        getTable()->key_info[i].rec_per_key[j]=
2570
 
          rec_per_key >= ~(ulong) 0 ? ~(ulong) 0 :
2571
 
          (ulong) rec_per_key;
2572
 
      }
2573
 
 
2574
 
      free(n_diff);
2575
 
    }
2576
 
  }
2577
 
 
2578
2524
  return(0);
2579
2525
}
2580
2526
 
2595
2541
      err= ib_cursor_open_table_using_id(table_id, transaction, &cursor);
2596
2542
 
2597
2543
      if (err != DB_SUCCESS)
2598
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2544
        return ib_err_t_to_drizzle_error(err);
2599
2545
 
2600
2546
    }
2601
2547
    else
2613
2559
                         getShare()->getKeyInfo(keynr).name,
2614
2560
                         &index_id);
2615
2561
    if (err != DB_SUCCESS)
2616
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2562
      return ib_err_t_to_drizzle_error(err);
2617
2563
 
2618
2564
    err= ib_cursor_close(cursor);
2619
2565
    assert(err == DB_SUCCESS);
2621
2567
    err= ib_cursor_open_index_using_id(index_id, transaction, &cursor);
2622
2568
 
2623
2569
    if (err != DB_SUCCESS)
2624
 
      return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2570
      return ib_err_t_to_drizzle_error(err);
2625
2571
 
2626
2572
    cursor_is_sec_index= true;
2627
2573
 
2774
2720
 
2775
2721
  if (err != DB_SUCCESS)
2776
2722
  {
2777
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2723
    return ib_err_t_to_drizzle_error(err);
2778
2724
  }
2779
2725
 
2780
2726
  tuple= ib_tuple_clear(tuple);
2781
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2782
 
                            getTable(),
 
2727
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2783
2728
                            share->has_hidden_primary_key,
2784
2729
                            &hidden_autoinc_pkey_position,
2785
2730
                            (allocate_blobs)? &blobroot : NULL);
2856
2801
  return 0;
2857
2802
}
2858
2803
 
2859
 
int HailDBCursor::analyze(Session*)
2860
 
{
2861
 
  ib_err_t err;
2862
 
 
2863
 
  err= ib_update_table_statistics(cursor);
2864
 
 
2865
 
  return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
2866
 
}
2867
 
 
2868
2804
int HailDBCursor::index_next(unsigned char *buf)
2869
2805
{
2870
2806
  int ret= HA_ERR_END_OF_FILE;
2877
2813
  }
2878
2814
 
2879
2815
  tuple= ib_tuple_clear(tuple);
2880
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2881
 
                            getTable(),
 
2816
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2882
2817
                            share->has_hidden_primary_key,
2883
2818
                            &hidden_autoinc_pkey_position);
2884
2819
 
2906
2841
      if (err == DB_END_OF_INDEX)
2907
2842
        return HA_ERR_END_OF_FILE;
2908
2843
      else
2909
 
        return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2844
        return ib_err_t_to_drizzle_error(err);
2910
2845
    }
2911
2846
  }
2912
2847
 
2913
2848
  tuple= ib_tuple_clear(tuple);
2914
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2915
 
                            getTable(),
 
2849
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2916
2850
                            share->has_hidden_primary_key,
2917
2851
                            &hidden_autoinc_pkey_position);
2918
2852
 
2929
2863
 
2930
2864
  err= ib_cursor_first(cursor);
2931
2865
  if (err != DB_SUCCESS)
2932
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2866
    return ib_err_t_to_drizzle_error(err);
2933
2867
 
2934
2868
  tuple= ib_tuple_clear(tuple);
2935
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2936
 
                            getTable(),
 
2869
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2937
2870
                            share->has_hidden_primary_key,
2938
2871
                            &hidden_autoinc_pkey_position);
2939
2872
 
2950
2883
 
2951
2884
  err= ib_cursor_last(cursor);
2952
2885
  if (err != DB_SUCCESS)
2953
 
    return ib_err_t_to_drizzle_error(getTable()->getSession(), err);
 
2886
    return ib_err_t_to_drizzle_error(err);
2954
2887
 
2955
2888
  tuple= ib_tuple_clear(tuple);
2956
 
  ret= read_row_from_haildb(getTable()->getSession(), buf, cursor, tuple,
2957
 
                            getTable(),
 
2889
  ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2958
2890
                            share->has_hidden_primary_key,
2959
2891
                            &hidden_autoinc_pkey_position);
2960
2892
  advance_cursor= true;
3147
3079
  bool r= false;
3148
3080
  va_list args;
3149
3081
  va_start(args, fmt);
3150
 
  if (not shutdown_in_progress)
3151
 
  {
3152
 
    r= plugin::ErrorMessage::vprintf(error::WARN, fmt, args);
3153
 
  }
 
3082
  if (! shutdown_in_progress)
 
3083
    r= plugin::ErrorMessage::vprintf(NULL, ERRMSG_LVL_WARN, fmt, args);
3154
3084
  else
3155
 
  {
3156
3085
    vfprintf(stderr, fmt, args);
3157
 
  }
3158
3086
  va_end(args);
3159
3087
 
3160
3088
  return (! r==true);
3539
3467
  "Transactional Storage Engine using the HailDB Library",
3540
3468
  PLUGIN_LICENSE_GPL,
3541
3469
  haildb_init,     /* Plugin Init */
3542
 
  NULL, /* depends */
 
3470
  NULL, /* system variables */
3543
3471
  init_options                /* config options   */
3544
3472
}
3545
3473
DRIZZLE_DECLARE_PLUGIN_END;