49
49
using namespace std;
50
50
using namespace drizzled;
52
/* Functions defined in this file */
52
/* Functions defined in this cursor */
54
54
void open_table_error(TableShare *share, int error, int db_errno,
55
55
myf errortype, int errarg);
161
161
field_type= DRIZZLE_TYPE_VARCHAR;
163
163
case message::Table::Field::DECIMAL:
164
field_type= DRIZZLE_TYPE_NEWDECIMAL;
164
field_type= DRIZZLE_TYPE_DECIMAL;
166
166
case message::Table::Field::ENUM:
167
167
field_type= DRIZZLE_TYPE_ENUM;
820
820
temp_table.s->db_low_byte_first= 1; //Cursor->low_byte_first();
821
821
temp_table.s->blob_ptr_size= portable_sizeof_char_ptr;
823
uint32_t field_length;
827
case DRIZZLE_TYPE_DOUBLE:
829
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
830
if (!fo.has_precision() && !fo.has_scale())
832
field_length= DBL_DIG+7;
836
field_length= fo.precision();
838
if (field_length < decimals &&
839
decimals != NOT_FIXED_DEC)
841
my_error(ER_M_BIGGER_THAN_D, MYF(0), pfield.name().c_str());
847
case DRIZZLE_TYPE_DECIMAL:
849
message::Table::Field::NumericFieldOptions fo= pfield.numeric_options();
851
field_length= my_decimal_precision_to_length(fo.precision(), fo.scale(),
856
field_length= pfield.options().length();
823
860
Field* f= make_field(share,
824
861
&share->mem_root,
825
862
record + field_offsets[fieldnr] + data_offset,
826
pfield.options().length(),
827
864
pfield.has_constraints() && pfield.constraints().is_nullable() ? true : false,
1156
1200
1 Error (see open_table_error)
1157
1201
2 Error (see open_table_error)
1158
3 Wrong data in .frm file
1202
3 Wrong data in .frm cursor
1159
1203
4 Error (see open_table_error)
1160
1204
5 Error (see open_table_error: charset unavailable)
1161
1205
6 Unknown .frm version
1235
1279
1 Error (see open_table_error)
1236
1280
2 Error (see open_table_error)
1237
3 Wrong data in .frm file
1281
3 Wrong data in .frm cursor
1238
1282
4 Error (see open_table_error)
1239
1283
5 Error (see open_table_error: charset unavailable)
1240
1284
7 Table definition has changed in engine
1398
1442
if (db_stat && open_mode != OTM_ALTER)
1401
if ((ha_err= (outparam->file->
1445
if ((ha_err= (outparam->cursor->
1402
1446
ha_open(outparam, share->normalized_path.str,
1403
1447
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1404
1448
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE :
1410
1454
/* Set a flag if the table is crashed and it can be auto. repaired */
1411
1455
share->crashed= ((ha_err == HA_ERR_CRASHED_ON_USAGE) &&
1412
outparam->file->auto_repair() &&
1456
outparam->cursor->auto_repair() &&
1413
1457
!(ha_open_flags & HA_OPEN_FOR_REPAIR));
1415
1459
switch (ha_err)
1427
1471
Too many files opened, use same error message as if the .frm
1431
1475
my_errno= EMFILE;
1434
outparam->file->print_error(ha_err, MYF(0));
1478
outparam->cursor->print_error(ha_err, MYF(0));
1435
1479
error_reported= true;
1436
1480
if (ha_err == HA_ERR_TABLE_DEF_CHANGED)
1453
1497
if (!error_reported && !(prgflag & DONT_GIVE_ERROR))
1454
1498
share->open_table_error(error, my_errno, 0);
1455
delete outparam->file;
1456
outparam->file= 0; // For easier error checking
1499
delete outparam->cursor;
1500
outparam->cursor= 0; // For easier error checking
1457
1501
outparam->db_stat= 0;
1458
1502
free_root(&outparam->mem_root, MYF(0)); // Safe to call on zeroed root
1459
1503
free((char*) outparam->alias);
1553
1597
ER_FILE_USED : ER_CANT_OPEN_FILE;
1554
1598
sprintf(buff,"%s%s", normalized_path.str,datext);
1555
1599
my_error(err_no,errortype, buff, db_errno);
1889
1933
void Table::prepare_for_position()
1892
if ((file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
1936
if ((cursor->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
1893
1937
s->primary_key < MAX_KEY)
1895
1939
mark_columns_used_by_index_no_reset(s->primary_key);
1913
1957
MyBitmap *bitmap= &tmp_set;
1915
(void) file->extra(HA_EXTRA_KEYREAD);
1959
(void) cursor->extra(HA_EXTRA_KEYREAD);
1916
1960
bitmap->clearAll();
1917
1961
mark_columns_used_by_index_no_reset(index, bitmap);
1918
1962
column_bitmaps_set(bitmap, bitmap);
2020
2064
mark_columns_used_by_index_no_reset(s->primary_key);
2022
2066
/* If we the engine wants all predicates we mark all keys */
2023
if (file->ha_table_flags() & HA_REQUIRES_KEY_COLUMNS_FOR_DELETE)
2067
if (cursor->ha_table_flags() & HA_REQUIRES_KEY_COLUMNS_FOR_DELETE)
2025
2069
Field **reg_field;
2026
2070
for (reg_field= field ; *reg_field ; reg_field++)
2551
2595
OPTION_BIG_TABLES || (select_options & TMP_TABLE_FORCE_MYISAM))
2553
2597
share->storage_engine= myisam_engine;
2554
table->file= share->db_type()->getCursor(share, &table->mem_root);
2598
table->cursor= share->db_type()->getCursor(*share, &table->mem_root);
2556
(param->group_parts > table->file->max_key_parts() ||
2557
param->group_length > table->file->max_key_length()))
2600
(param->group_parts > table->cursor->max_key_parts() ||
2601
param->group_length > table->cursor->max_key_length()))
2558
2602
using_unique_constraint=1;
2562
2606
share->storage_engine= heap_engine;
2563
table->file= share->db_type()->getCursor(share, &table->mem_root);
2607
table->cursor= share->db_type()->getCursor(*share, &table->mem_root);
3041
3085
bool Table::open_tmp_table()
3044
if ((error=file->ha_open(this, s->table_name.str,O_RDWR,
3088
if ((error=cursor->ha_open(this, s->table_name.str,O_RDWR,
3045
3089
HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
3047
file->print_error(error,MYF(0));
3091
cursor->print_error(error,MYF(0));
3051
(void) file->extra(HA_EXTRA_QUICK); /* Faster */
3095
(void) cursor->extra(HA_EXTRA_QUICK); /* Faster */
3103
3147
memset(seg, 0, sizeof(*seg) * keyinfo->key_parts);
3104
if (keyinfo->key_length >= file->max_key_length() ||
3105
keyinfo->key_parts > file->max_key_parts() ||
3148
if (keyinfo->key_length >= cursor->max_key_length() ||
3149
keyinfo->key_parts > cursor->max_key_parts() ||
3106
3150
share->uniques)
3108
3152
/* Can't create a key; Make a unique constraint instead of a key */
3200
3244
// Release latches since this can take a long time
3201
3245
plugin::StorageEngine::releaseTemporaryLatches(session);
3206
file->closeMarkForDelete(s->table_name.str);
3250
cursor->closeMarkForDelete(s->table_name.str);
3208
3252
s->db_type()->doDropTable(*session, s->table_name.str);
3213
3257
/* free blobs */
3237
3281
if (table->s->db_type() != heap_engine ||
3238
3282
error != HA_ERR_RECORD_FILE_FULL)
3240
table->file->print_error(error,MYF(0));
3284
table->cursor->print_error(error,MYF(0));
3248
3292
share= *table->s;
3249
3293
new_table.s= &share;
3250
3294
new_table.s->storage_engine= myisam_engine;
3251
if (!(new_table.file= new_table.s->db_type()->getCursor(&share, &new_table.mem_root)))
3295
if (!(new_table.cursor= new_table.s->db_type()->getCursor(share, &new_table.mem_root)))
3252
3296
return true; // End of memory
3254
3298
save_proc_info=session->get_proc_info();
3261
3305
if (new_table.open_tmp_table())
3263
if (table->file->indexes_are_disabled())
3264
new_table.file->ha_disable_indexes(HA_KEY_SWITCH_ALL);
3265
table->file->ha_index_or_rnd_end();
3266
table->file->ha_rnd_init(1);
3307
if (table->cursor->indexes_are_disabled())
3308
new_table.cursor->ha_disable_indexes(HA_KEY_SWITCH_ALL);
3309
table->cursor->ha_index_or_rnd_end();
3310
table->cursor->ha_rnd_init(1);
3267
3311
if (table->no_rows)
3269
new_table.file->extra(HA_EXTRA_NO_ROWS);
3313
new_table.cursor->extra(HA_EXTRA_NO_ROWS);
3270
3314
new_table.no_rows=1;
3273
3317
/* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */
3274
new_table.file->extra(HA_EXTRA_WRITE_CACHE);
3318
new_table.cursor->extra(HA_EXTRA_WRITE_CACHE);
3277
3321
copy all old rows from heap table to MyISAM table
3278
3322
This is the only code that uses record[1] to read/write but this
3279
3323
is safe as this is a temporary MyISAM table without timestamp/autoincrement.
3281
while (!table->file->rnd_next(new_table.record[1]))
3325
while (!table->cursor->rnd_next(new_table.record[1]))
3283
write_err= new_table.file->ha_write_row(new_table.record[1]);
3327
write_err= new_table.cursor->ha_write_row(new_table.record[1]);
3287
3331
/* copy row that filled HEAP table */
3288
if ((write_err=new_table.file->ha_write_row(table->record[0])))
3332
if ((write_err=new_table.cursor->ha_write_row(table->record[0])))
3290
if (new_table.file->is_fatal_error(write_err, HA_CHECK_DUP) ||
3334
if (new_table.cursor->is_fatal_error(write_err, HA_CHECK_DUP) ||
3291
3335
!ignore_last_dupp_key_error)
3295
3339
/* remove heap table and change to use myisam table */
3296
(void) table->file->ha_rnd_end();
3297
(void) table->file->close(); // This deletes the table !
3340
(void) table->cursor->ha_rnd_end();
3341
(void) table->cursor->close(); // This deletes the table !
3342
delete table->cursor;
3343
table->cursor= NULL;
3300
3344
new_table.s= table->s; // Keep old share
3301
3345
*table= new_table;
3302
3346
*table->s= share;
3304
table->file->change_table_ptr(table, table->s);
3348
table->cursor->change_table_ptr(table, table->s);
3305
3349
table->use_all_columns();
3306
3350
if (save_proc_info)
3316
table->file->print_error(write_err, MYF(0));
3317
(void) table->file->ha_rnd_end();
3318
(void) new_table.file->close();
3360
table->cursor->print_error(write_err, MYF(0));
3361
(void) table->cursor->ha_rnd_end();
3362
(void) new_table.cursor->close();
3320
3364
new_table.s->db_type()->doDropTable(*session, new_table.s->table_name.str);
3322
delete new_table.file;
3366
delete new_table.cursor;
3323
3367
session->set_proc_info(save_proc_info);
3324
3368
table->mem_root= new_table.mem_root;
3473
3517
if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
3474
3518
errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
3475
3519
error, s->path.str);
3476
file->print_error(error,MYF(0));
3520
cursor->print_error(error,MYF(0));