91
91
#include "drizzled/global_charset_info.h"
93
#include "haildb_version_func.h"
93
94
#include "haildb_datadict_dump_func.h"
94
95
#include "config_table_function.h"
95
96
#include "status_table_function.h"
98
#if defined(HAVE_HAILDB_H)
101
# include <embedded_innodb-1.0/innodb.h>
102
#endif /* HAVE_HAILDB_H */
99
104
#include "haildb_engine.h"
477
ib_trx_t transaction= *get_trx(getTable()->in_use);
482
ib_trx_t transaction= *get_trx(table->in_use);
478
483
ib_cursor_attach_trx(cursor, transaction);
479
484
tuple= ib_clust_read_tuple_create(cursor);
480
485
err= ib_cursor_last(cursor);
487
492
assert (err == DB_SUCCESS);
488
err= ib_tuple_read_u64(tuple, getTable()->getShare()->fields, &nr);
493
err= ib_tuple_read_u64(tuple, table->getShare()->fields, &nr);
491
496
ib_tuple_delete(tuple);
502
507
(void) extra(HA_EXTRA_KEYREAD);
503
getTable()->mark_columns_used_by_index_no_reset(getTable()->getShare()->next_number_index);
504
doStartIndexScan(getTable()->getShare()->next_number_index, 1);
505
if (getTable()->getShare()->next_number_keypart == 0)
508
table->mark_columns_used_by_index_no_reset(table->getShare()->next_number_index);
509
doStartIndexScan(table->getShare()->next_number_index, 1);
510
if (table->getShare()->next_number_keypart == 0)
506
511
{ // Autoincrement at key-start
507
error=index_last(getTable()->getUpdateRecord());
512
error=index_last(table->getUpdateRecord());
511
516
unsigned char key[MAX_KEY_LENGTH];
512
key_copy(key, getTable()->getInsertRecord(),
513
getTable()->key_info + getTable()->getShare()->next_number_index,
514
getTable()->getShare()->next_number_key_offset);
515
error= index_read_map(getTable()->getUpdateRecord(), key,
516
make_prev_keypart_map(getTable()->getShare()->next_number_keypart),
517
key_copy(key, table->getInsertRecord(),
518
table->key_info + table->getShare()->next_number_index,
519
table->getShare()->next_number_key_offset);
520
error= index_read_map(table->getUpdateRecord(), key,
521
make_prev_keypart_map(table->getShare()->next_number_keypart),
517
522
HA_READ_PREFIX_LAST);
523
nr= ((uint64_t) getTable()->found_next_number_field->
524
val_int_offset(getTable()->getShare()->rec_buff_length)+1);
528
nr= ((uint64_t) table->found_next_number_field->
529
val_int_offset(table->getShare()->rec_buff_length)+1);
525
530
doEndIndexScan();
526
531
(void) extra(HA_EXTRA_NO_KEYREAD);
528
if (getTable()->getShare()->getTableProto()->options().auto_increment_value() > nr)
529
nr= getTable()->getShare()->getTableProto()->options().auto_increment_value();
533
if (table->getShare()->getTableProto()->options().auto_increment_value() > nr)
534
nr= table->getShare()->getTableProto()->options().auto_increment_value();
798
803
HailDBCursor::HailDBCursor(drizzled::plugin::StorageEngine &engine_arg,
804
TableShare &table_arg)
800
805
:Cursor(engine_arg, table_arg),
801
806
ib_lock_mode(IB_LOCK_NONE),
802
807
write_can_replace(false),
836
841
lock.init(&share->lock);
839
if (getTable()->getShare()->getPrimaryKey() != MAX_KEY)
840
ref_length= getTable()->key_info[getTable()->getShare()->getPrimaryKey()].key_length;
844
if (table->getShare()->getPrimaryKey() != MAX_KEY)
845
ref_length= table->key_info[table->getShare()->getPrimaryKey()].key_length;
841
846
else if (share->has_hidden_primary_key)
842
847
ref_length= sizeof(uint64_t);
845
unsigned int keynr= get_first_unique_index(*getTable());
846
ref_length= getTable()->key_info[keynr].key_length;
850
unsigned int keynr= get_first_unique_index(*table);
851
ref_length= table->key_info[keynr].key_length;
849
854
in_table_scan= false;
1897
HailDBEngine *storage_engine= static_cast<HailDBEngine*>(getEngine());
1902
HailDBEngine *storage_engine= static_cast<HailDBEngine*>(engine);
1898
1903
err= ib_cursor_reset(cursor);
1899
1904
storage_engine->doCommit(current_session, true);
1900
1905
storage_engine->doStartTransaction(current_session, START_TRANS_NO_OPTIONS);
1901
transaction= *get_trx(getTable()->in_use);
1906
transaction= *get_trx(table->in_use);
1902
1907
assert(err == DB_SUCCESS);
1903
1908
ib_cursor_attach_trx(cursor, transaction);
1904
1909
err= ib_cursor_first(cursor);
1907
1912
assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
1910
if (getTable()->next_number_field)
1915
if (table->next_number_field)
1912
1917
update_auto_increment();
1914
uint64_t temp_auto= getTable()->next_number_field->val_int();
1919
uint64_t temp_auto= table->next_number_field->val_int();
1916
if (temp_auto <= innobase_get_int_col_max_value(getTable()->next_number_field))
1921
if (temp_auto <= innobase_get_int_col_max_value(table->next_number_field))
1938
write_row_to_haildb_tuple(getTable()->getFields(), tuple);
1943
write_row_to_haildb_tuple(table->getFields(), tuple);
1940
1945
if (share->has_hidden_primary_key)
1942
err= ib_tuple_write_u64(tuple, getTable()->getShare()->fields, share->hidden_pkey_auto_increment_value.fetch_and_increment());
1947
err= ib_tuple_write_u64(tuple, table->getShare()->fields, share->hidden_pkey_auto_increment_value.fetch_and_increment());
1945
1950
err= ib_cursor_insert_row(cursor, tuple);
1949
1954
if (write_can_replace)
1951
store_key_value_from_haildb(getTable()->key_info + getTable()->getShare()->getPrimaryKey(),
1956
store_key_value_from_haildb(table->key_info + table->getShare()->getPrimaryKey(),
1952
1957
ref, ref_length, record);
1954
1959
ib_tpl_t search_tuple= ib_clust_search_tuple_create(cursor);
1956
1961
fill_ib_search_tpl_from_drizzle_key(search_tuple,
1957
getTable()->key_info + 0,
1962
table->key_info + 0,
1958
1963
ref, ref_length);
1968
1973
err= ib_cursor_first(cursor);
1969
1974
assert(err == DB_SUCCESS || err == DB_END_OF_INDEX);
1971
write_row_to_haildb_tuple(getTable()->getFields(), tuple);
1976
write_row_to_haildb_tuple(table->getFields(), tuple);
1973
1978
err= ib_cursor_insert_row(cursor, tuple);
1974
1979
assert(err==DB_SUCCESS); // probably be nice and process errors
1997
2002
err= ib_tuple_copy(update_tuple, tuple);
1998
2003
assert(err == DB_SUCCESS);
2000
write_row_to_haildb_tuple(getTable()->getFields(), update_tuple);
2005
write_row_to_haildb_tuple(table->getFields(), update_tuple);
2002
2007
err= ib_cursor_update_row(cursor, tuple, update_tuple);
2031
2036
so only support TRUNCATE and not DELETE FROM t;
2032
2037
(this is what ha_haildb does)
2034
if (session_sql_command(getTable()->in_use) != SQLCOM_TRUNCATE)
2039
if (session_sql_command(table->in_use) != SQLCOM_TRUNCATE)
2035
2040
return HA_ERR_WRONG_COMMAND;
2047
2052
ib_err_t rollback_err= ib_trx_rollback(transaction);
2049
push_warning_printf(getTable()->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2054
push_warning_printf(table->in_use, DRIZZLE_ERROR::WARN_LEVEL_ERROR,
2050
2055
ER_CANT_DELETE_FILE,
2051
2056
_("Cannot Lock HailDB Data Dictionary. HailDB Error %d (%s)\n"),
2052
2057
err, ib_strerror(err));
2206
2211
err= ib_cursor_next(cursor);
2208
2213
tuple= ib_tuple_clear(tuple);
2209
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2214
ret= read_row_from_haildb(buf, cursor, tuple, table,
2210
2215
share->has_hidden_primary_key,
2211
2216
&hidden_autoinc_pkey_position);
2243
2248
unsigned int keynr;
2244
if (getTable()->getShare()->getPrimaryKey() != MAX_KEY)
2245
keynr= getTable()->getShare()->getPrimaryKey();
2249
if (table->getShare()->getPrimaryKey() != MAX_KEY)
2250
keynr= table->getShare()->getPrimaryKey();
2247
keynr= get_first_unique_index(*getTable());
2252
keynr= get_first_unique_index(*table);
2249
2254
fill_ib_search_tpl_from_drizzle_key(search_tuple,
2250
getTable()->key_info + keynr,
2255
table->key_info + keynr,
2251
2256
pos, ref_length);
2263
2268
tuple= ib_tuple_clear(tuple);
2266
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2271
ret= read_row_from_haildb(buf, cursor, tuple, table,
2267
2272
share->has_hidden_primary_key,
2268
2273
&hidden_autoinc_pkey_position);
2336
2341
unsigned int keynr;
2337
if (getTable()->getShare()->getPrimaryKey() != MAX_KEY)
2338
keynr= getTable()->getShare()->getPrimaryKey();
2342
if (table->getShare()->getPrimaryKey() != MAX_KEY)
2343
keynr= table->getShare()->getPrimaryKey();
2340
keynr= get_first_unique_index(*getTable());
2345
keynr= get_first_unique_index(*table);
2342
store_key_value_from_haildb(getTable()->key_info + keynr,
2347
store_key_value_from_haildb(table->key_info + keynr,
2343
2348
ref, ref_length, record);
2349
2354
double HailDBCursor::scan_time()
2351
ib_table_stats_t table_stats;
2354
err= ib_get_table_statistics(cursor, &table_stats, sizeof(table_stats));
2356
/* Approximate I/O seeks for full table scan */
2357
return (double) (table_stats.stat_clustered_index_size / 16384);
2360
2359
int HailDBCursor::info(uint32_t flag)
2362
ib_table_stats_t table_stats;
2365
if (flag & HA_STATUS_VARIABLE)
2367
err= ib_get_table_statistics(cursor, &table_stats, sizeof(table_stats));
2369
stats.records= table_stats.stat_n_rows;
2371
if (table_stats.stat_n_rows < 2)
2375
stats.data_file_length= table_stats.stat_clustered_index_size;
2376
stats.index_file_length= table_stats.stat_sum_of_other_index_sizes;
2378
stats.mean_rec_length= stats.data_file_length / stats.records;
2381
2363
if (flag & HA_STATUS_AUTO)
2382
2364
stats.auto_increment_value= 1;
2401
2383
ib_id_t index_id;
2402
err= ib_index_get_id(table_path_to_haildb_name(getShare()->getPath()),
2403
getShare()->getKeyInfo(keynr).name,
2384
err= ib_index_get_id(table_path_to_haildb_name(table_share->getPath()),
2385
table_share->getKeyInfo(keynr).name,
2405
2387
if (err != DB_SUCCESS)
2547
2529
search_tuple= ib_sec_search_tuple_create(cursor);
2549
2531
fill_ib_search_tpl_from_drizzle_key(search_tuple,
2550
getTable()->key_info + active_index,
2532
table->key_info + active_index,
2551
2533
key_ptr, key_len);
2553
2535
err= ib_cursor_moveto(cursor, search_tuple, search_mode, &res);
2567
2549
tuple= ib_tuple_clear(tuple);
2568
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2550
ret= read_row_from_haildb(buf, cursor, tuple, table,
2569
2551
share->has_hidden_primary_key,
2570
2552
&hidden_autoinc_pkey_position,
2571
2553
(allocate_blobs)? &blobroot : NULL);
2573
getTable()->status= 0;
2575
getTable()->status= STATUS_NOT_FOUND;
2557
table->status= STATUS_NOT_FOUND;
2577
2559
advance_cursor= true;
2594
2576
/* works only with key prefixes */
2595
2577
assert(((keypart_map_arg + 1) & keypart_map_arg) == 0);
2597
KeyPartInfo *key_part_found= getTable()->getShare()->getKeyInfo(key_position).key_part;
2598
KeyPartInfo *end_key_part_found= key_part_found + getTable()->getShare()->getKeyInfo(key_position).key_parts;
2579
KeyPartInfo *key_part_found= table->getShare()->getKeyInfo(key_position).key_part;
2580
KeyPartInfo *end_key_part_found= key_part_found + table->getShare()->getKeyInfo(key_position).key_parts;
2599
2581
uint32_t length= 0;
2601
2583
while (key_part_found < end_key_part_found && keypart_map_arg)
2656
2638
tuple= ib_tuple_clear(tuple);
2657
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2639
ret= read_row_from_haildb(buf, cursor, tuple, table,
2658
2640
share->has_hidden_primary_key,
2659
2641
&hidden_autoinc_pkey_position);
2689
2671
tuple= ib_tuple_clear(tuple);
2690
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2672
ret= read_row_from_haildb(buf, cursor, tuple, table,
2691
2673
share->has_hidden_primary_key,
2692
2674
&hidden_autoinc_pkey_position);
2707
2689
return ib_err_t_to_drizzle_error(err);
2709
2691
tuple= ib_tuple_clear(tuple);
2710
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2692
ret= read_row_from_haildb(buf, cursor, tuple, table,
2711
2693
share->has_hidden_primary_key,
2712
2694
&hidden_autoinc_pkey_position);
2727
2709
return ib_err_t_to_drizzle_error(err);
2729
2711
tuple= ib_tuple_clear(tuple);
2730
ret= read_row_from_haildb(buf, cursor, tuple, getTable(),
2712
ret= read_row_from_haildb(buf, cursor, tuple, table,
2731
2713
share->has_hidden_primary_key,
2732
2714
&hidden_autoinc_pkey_position);
2733
2715
advance_cursor= true;
3237
3219
haildb_engine= new HailDBEngine("InnoDB");
3238
3220
context.add(haildb_engine);
3222
haildb_version_func_initialize(context);
3240
3223
haildb_datadict_dump_func_initialize(context);
3241
3224
config_table_function_initialize(context);
3242
3225
status_table_function_initialize(context);