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
1193
1 Error (see open_table_error)
1157
1194
2 Error (see open_table_error)
1158
3 Wrong data in .frm file
1195
3 Wrong data in .frm cursor
1159
1196
4 Error (see open_table_error)
1160
1197
5 Error (see open_table_error: charset unavailable)
1161
1198
6 Unknown .frm version
1235
1272
1 Error (see open_table_error)
1236
1273
2 Error (see open_table_error)
1237
3 Wrong data in .frm file
1274
3 Wrong data in .frm cursor
1238
1275
4 Error (see open_table_error)
1239
1276
5 Error (see open_table_error: charset unavailable)
1240
1277
7 Table definition has changed in engine
1398
1435
if (db_stat && open_mode != OTM_ALTER)
1401
if ((ha_err= (outparam->file->
1438
if ((ha_err= (outparam->cursor->
1402
1439
ha_open(outparam, share->normalized_path.str,
1403
1440
(db_stat & HA_READ_ONLY ? O_RDONLY : O_RDWR),
1404
1441
(db_stat & HA_OPEN_TEMPORARY ? HA_OPEN_TMP_TABLE :
1410
1447
/* Set a flag if the table is crashed and it can be auto. repaired */
1411
1448
share->crashed= ((ha_err == HA_ERR_CRASHED_ON_USAGE) &&
1412
outparam->file->auto_repair() &&
1449
outparam->cursor->auto_repair() &&
1413
1450
!(ha_open_flags & HA_OPEN_FOR_REPAIR));
1415
1452
switch (ha_err)
1427
1464
Too many files opened, use same error message as if the .frm
1431
1468
my_errno= EMFILE;
1434
outparam->file->print_error(ha_err, MYF(0));
1471
outparam->cursor->print_error(ha_err, MYF(0));
1435
1472
error_reported= true;
1436
1473
if (ha_err == HA_ERR_TABLE_DEF_CHANGED)
1453
1490
if (!error_reported && !(prgflag & DONT_GIVE_ERROR))
1454
1491
share->open_table_error(error, my_errno, 0);
1455
delete outparam->file;
1456
outparam->file= 0; // For easier error checking
1492
delete outparam->cursor;
1493
outparam->cursor= 0; // For easier error checking
1457
1494
outparam->db_stat= 0;
1458
1495
free_root(&outparam->mem_root, MYF(0)); // Safe to call on zeroed root
1459
1496
free((char*) outparam->alias);
1553
1590
ER_FILE_USED : ER_CANT_OPEN_FILE;
1554
1591
sprintf(buff,"%s%s", normalized_path.str,datext);
1555
1592
my_error(err_no,errortype, buff, db_errno);
1889
1926
void Table::prepare_for_position()
1892
if ((file->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
1929
if ((cursor->ha_table_flags() & HA_PRIMARY_KEY_IN_READ_INDEX) &&
1893
1930
s->primary_key < MAX_KEY)
1895
1932
mark_columns_used_by_index_no_reset(s->primary_key);
1913
1950
MyBitmap *bitmap= &tmp_set;
1915
(void) file->extra(HA_EXTRA_KEYREAD);
1952
(void) cursor->extra(HA_EXTRA_KEYREAD);
1916
1953
bitmap->clearAll();
1917
1954
mark_columns_used_by_index_no_reset(index, bitmap);
1918
1955
column_bitmaps_set(bitmap, bitmap);
2020
2057
mark_columns_used_by_index_no_reset(s->primary_key);
2022
2059
/* If we the engine wants all predicates we mark all keys */
2023
if (file->ha_table_flags() & HA_REQUIRES_KEY_COLUMNS_FOR_DELETE)
2060
if (cursor->ha_table_flags() & HA_REQUIRES_KEY_COLUMNS_FOR_DELETE)
2025
2062
Field **reg_field;
2026
2063
for (reg_field= field ; *reg_field ; reg_field++)
2551
2588
OPTION_BIG_TABLES || (select_options & TMP_TABLE_FORCE_MYISAM))
2553
2590
share->storage_engine= myisam_engine;
2554
table->file= share->db_type()->getCursor(share, &table->mem_root);
2591
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()))
2593
(param->group_parts > table->cursor->max_key_parts() ||
2594
param->group_length > table->cursor->max_key_length()))
2558
2595
using_unique_constraint=1;
2562
2599
share->storage_engine= heap_engine;
2563
table->file= share->db_type()->getCursor(share, &table->mem_root);
2600
table->cursor= share->db_type()->getCursor(*share, &table->mem_root);
3041
3078
bool Table::open_tmp_table()
3044
if ((error=file->ha_open(this, s->table_name.str,O_RDWR,
3081
if ((error=cursor->ha_open(this, s->table_name.str,O_RDWR,
3045
3082
HA_OPEN_TMP_TABLE | HA_OPEN_INTERNAL_TABLE)))
3047
file->print_error(error,MYF(0));
3084
cursor->print_error(error,MYF(0));
3051
(void) file->extra(HA_EXTRA_QUICK); /* Faster */
3088
(void) cursor->extra(HA_EXTRA_QUICK); /* Faster */
3103
3140
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() ||
3141
if (keyinfo->key_length >= cursor->max_key_length() ||
3142
keyinfo->key_parts > cursor->max_key_parts() ||
3106
3143
share->uniques)
3108
3145
/* Can't create a key; Make a unique constraint instead of a key */
3200
3237
// Release latches since this can take a long time
3201
3238
plugin::StorageEngine::releaseTemporaryLatches(session);
3206
file->closeMarkForDelete(s->table_name.str);
3243
cursor->closeMarkForDelete(s->table_name.str);
3208
3245
s->db_type()->doDropTable(*session, s->table_name.str);
3213
3250
/* free blobs */
3237
3274
if (table->s->db_type() != heap_engine ||
3238
3275
error != HA_ERR_RECORD_FILE_FULL)
3240
table->file->print_error(error,MYF(0));
3277
table->cursor->print_error(error,MYF(0));
3248
3285
share= *table->s;
3249
3286
new_table.s= &share;
3250
3287
new_table.s->storage_engine= myisam_engine;
3251
if (!(new_table.file= new_table.s->db_type()->getCursor(&share, &new_table.mem_root)))
3288
if (!(new_table.cursor= new_table.s->db_type()->getCursor(share, &new_table.mem_root)))
3252
3289
return true; // End of memory
3254
3291
save_proc_info=session->get_proc_info();
3261
3298
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);
3300
if (table->cursor->indexes_are_disabled())
3301
new_table.cursor->ha_disable_indexes(HA_KEY_SWITCH_ALL);
3302
table->cursor->ha_index_or_rnd_end();
3303
table->cursor->ha_rnd_init(1);
3267
3304
if (table->no_rows)
3269
new_table.file->extra(HA_EXTRA_NO_ROWS);
3306
new_table.cursor->extra(HA_EXTRA_NO_ROWS);
3270
3307
new_table.no_rows=1;
3273
3310
/* HA_EXTRA_WRITE_CACHE can stay until close, no need to disable it */
3274
new_table.file->extra(HA_EXTRA_WRITE_CACHE);
3311
new_table.cursor->extra(HA_EXTRA_WRITE_CACHE);
3277
3314
copy all old rows from heap table to MyISAM table
3278
3315
This is the only code that uses record[1] to read/write but this
3279
3316
is safe as this is a temporary MyISAM table without timestamp/autoincrement.
3281
while (!table->file->rnd_next(new_table.record[1]))
3318
while (!table->cursor->rnd_next(new_table.record[1]))
3283
write_err= new_table.file->ha_write_row(new_table.record[1]);
3320
write_err= new_table.cursor->ha_write_row(new_table.record[1]);
3287
3324
/* copy row that filled HEAP table */
3288
if ((write_err=new_table.file->ha_write_row(table->record[0])))
3325
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) ||
3327
if (new_table.cursor->is_fatal_error(write_err, HA_CHECK_DUP) ||
3291
3328
!ignore_last_dupp_key_error)
3295
3332
/* 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 !
3333
(void) table->cursor->ha_rnd_end();
3334
(void) table->cursor->close(); // This deletes the table !
3335
delete table->cursor;
3336
table->cursor= NULL;
3300
3337
new_table.s= table->s; // Keep old share
3301
3338
*table= new_table;
3302
3339
*table->s= share;
3304
table->file->change_table_ptr(table, table->s);
3341
table->cursor->change_table_ptr(table, table->s);
3305
3342
table->use_all_columns();
3306
3343
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();
3353
table->cursor->print_error(write_err, MYF(0));
3354
(void) table->cursor->ha_rnd_end();
3355
(void) new_table.cursor->close();
3320
3357
new_table.s->db_type()->doDropTable(*session, new_table.s->table_name.str);
3322
delete new_table.file;
3359
delete new_table.cursor;
3323
3360
session->set_proc_info(save_proc_info);
3324
3361
table->mem_root= new_table.mem_root;
3473
3510
if (error != HA_ERR_LOCK_DEADLOCK && error != HA_ERR_LOCK_WAIT_TIMEOUT)
3474
3511
errmsg_printf(ERRMSG_LVL_ERROR, _("Got error %d when reading table '%s'"),
3475
3512
error, s->path.str);
3476
file->print_error(error,MYF(0));
3513
cursor->print_error(error,MYF(0));