~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/innobase/include/row0mysql.h

  • Committer: Monty Taylor
  • Date: 2008-09-15 17:24:04 UTC
  • Revision ID: monty@inaugust.com-20080915172404-ygh6hiyu0q7qpa9x
Removed strndup calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
/***********************************************************************
27
27
Frees the blob heap in prebuilt when no longer needed. */
28
 
UNIV_INTERN
 
28
 
29
29
void
30
30
row_mysql_prebuilt_free_blob_heap(
31
31
/*==============================*/
34
34
/***********************************************************************
35
35
Stores a >= 5.0.3 format true VARCHAR length to dest, in the MySQL row
36
36
format. */
37
 
UNIV_INTERN
 
37
 
38
38
byte*
39
39
row_mysql_store_true_var_len(
40
40
/*=========================*/
47
47
Reads a >= 5.0.3 format true VARCHAR length, in the MySQL row format, and
48
48
returns a pointer to the data. */
49
49
 
50
 
const byte*
 
50
byte*
51
51
row_mysql_read_true_varchar(
52
52
/*========================*/
53
 
                                /* out: pointer to the data, we skip
54
 
                                the 1 or 2 bytes at the start that are
55
 
                                used to store the len */
56
 
        ulint*          len,    /* out: variable-length field length */
57
 
        const byte*     field,  /* in: field in the MySQL format */
58
 
        ulint           lenlen);/* in: storage length of len: either 1
59
 
                                or 2 bytes */
 
53
                        /* out: pointer to the data, we skip the 1 or 2 bytes
 
54
                        at the start that are used to store the len */
 
55
        ulint*  len,    /* out: variable-length field length */
 
56
        byte*   field,  /* in: field in the MySQL format */
 
57
        ulint   lenlen);/* in: storage length of len: either 1 or 2 bytes */
60
58
/***********************************************************************
61
59
Stores a reference to a BLOB in the MySQL format. */
62
 
UNIV_INTERN
 
60
 
63
61
void
64
62
row_mysql_store_blob_ref(
65
63
/*=====================*/
66
 
        byte*           dest,   /* in: where to store */
67
 
        ulint           col_len,/* in: dest buffer size: determines into
 
64
        byte*   dest,           /* in: where to store */
 
65
        ulint   col_len,        /* in: dest buffer size: determines into
68
66
                                how many bytes the BLOB length is stored,
69
 
                                the space for the length may vary from 1
70
 
                                to 4 bytes */
71
 
        const void*     data,   /* in: BLOB data; if the value to store
72
 
                                is SQL NULL this should be NULL pointer */
73
 
        ulint           len);   /* in: BLOB length; if the value to store
74
 
                                is SQL NULL this should be 0; remember
75
 
                                also to set the NULL bit in the MySQL record
76
 
                                header! */
 
67
                                this may vary from 1 to 4 bytes */
 
68
        byte*   data,           /* in: BLOB data */
 
69
        ulint   len);           /* in: BLOB length */
77
70
/***********************************************************************
78
71
Reads a reference to a BLOB in the MySQL format. */
79
72
 
80
 
const byte*
 
73
byte*
81
74
row_mysql_read_blob_ref(
82
75
/*====================*/
83
 
                                        /* out: pointer to BLOB data */
84
 
        ulint*          len,            /* out: BLOB length */
85
 
        const byte*     ref,            /* in: BLOB reference in the
86
 
                                        MySQL format */
87
 
        ulint           col_len);       /* in: BLOB reference length
88
 
                                        (not BLOB length) */
 
76
                                /* out: pointer to BLOB data */
 
77
        ulint*  len,            /* out: BLOB length */
 
78
        byte*   ref,            /* in: BLOB reference in the MySQL format */
 
79
        ulint   col_len);       /* in: BLOB reference length (not BLOB
 
80
                                length) */
89
81
/******************************************************************
90
82
Stores a non-SQL-NULL field given in the MySQL format in the InnoDB format.
91
83
The counterpart of this function is row_sel_field_store_in_mysql_format() in
92
84
row0sel.c. */
93
 
UNIV_INTERN
 
85
 
94
86
byte*
95
87
row_mysql_store_col_in_innobase_format(
96
88
/*===================================*/
109
101
                                        format differs in a row and in a
110
102
                                        key value: in a key value the length
111
103
                                        is always stored in 2 bytes! */
112
 
        const byte*     mysql_data,     /* in: MySQL column value, not
 
104
        byte*           mysql_data,     /* in: MySQL column value, not
113
105
                                        SQL NULL; NOTE that dfield may also
114
106
                                        get a pointer to mysql_data,
115
107
                                        therefore do not discard this as long
123
115
        ulint           comp);          /* in: nonzero=compact format */
124
116
/********************************************************************
125
117
Handles user errors and lock waits detected by the database engine. */
126
 
UNIV_INTERN
 
118
 
127
119
ibool
128
120
row_mysql_handle_errors(
129
121
/*====================*/
137
129
        trx_savept_t*   savept);/* in: savepoint */
138
130
/************************************************************************
139
131
Create a prebuilt struct for a MySQL table handle. */
140
 
UNIV_INTERN
 
132
 
141
133
row_prebuilt_t*
142
134
row_create_prebuilt(
143
135
/*================*/
145
137
        dict_table_t*   table); /* in: Innobase table handle */
146
138
/************************************************************************
147
139
Free a prebuilt struct for a MySQL table handle. */
148
 
UNIV_INTERN
 
140
 
149
141
void
150
142
row_prebuilt_free(
151
143
/*==============*/
152
 
        row_prebuilt_t* prebuilt,       /* in, own: prebuilt struct */
153
 
        ibool           dict_locked);   /* in: TRUE=data dictionary locked */
 
144
        row_prebuilt_t* prebuilt);      /* in, own: prebuilt struct */
154
145
/*************************************************************************
155
146
Updates the transaction pointers in query graphs stored in the prebuilt
156
147
struct. */
157
 
UNIV_INTERN
 
148
 
158
149
void
159
150
row_update_prebuilt_trx(
160
151
/*====================*/
164
155
        trx_t*          trx);           /* in: transaction handle */
165
156
/*************************************************************************
166
157
Unlocks an AUTO_INC type lock possibly reserved by trx. */
167
 
UNIV_INTERN
 
158
 
168
159
void
169
160
row_unlock_table_autoinc_for_mysql(
170
161
/*===============================*/
175
166
table. The lock is reserved only for the duration of an SQL statement.
176
167
It is not compatible with another AUTO_INC or exclusive lock on the
177
168
table. */
178
 
UNIV_INTERN
 
169
 
179
170
int
180
171
row_lock_table_autoinc_for_mysql(
181
172
/*=============================*/
184
175
                                        table handle */
185
176
/*************************************************************************
186
177
Sets a table lock on the table mentioned in prebuilt. */
187
 
UNIV_INTERN
 
178
 
188
179
int
189
180
row_lock_table_for_mysql(
190
181
/*=====================*/
200
191
 
201
192
/*************************************************************************
202
193
Does an insert for MySQL. */
203
 
UNIV_INTERN
 
194
 
204
195
int
205
196
row_insert_for_mysql(
206
197
/*=================*/
210
201
                                        handle */
211
202
/*************************************************************************
212
203
Builds a dummy query graph used in selects. */
213
 
UNIV_INTERN
 
204
 
214
205
void
215
206
row_prebuild_sel_graph(
216
207
/*===================*/
220
211
Gets pointer to a prebuilt update vector used in updates. If the update
221
212
graph has not yet been built in the prebuilt struct, then this function
222
213
first builds it. */
223
 
UNIV_INTERN
 
214
 
224
215
upd_t*
225
216
row_get_prebuilt_update_vector(
226
217
/*===========================*/
230
221
/*************************************************************************
231
222
Checks if a table is such that we automatically created a clustered
232
223
index on it (on row id). */
233
 
UNIV_INTERN
 
224
 
234
225
ibool
235
226
row_table_got_default_clust_index(
236
227
/*==============================*/
237
 
        const dict_table_t*     table);
 
228
        dict_table_t*   table);
238
229
/*************************************************************************
239
230
Calculates the key number used inside MySQL for an Innobase index. We have
240
231
to take into account if we generated a default clustered index for the table */
241
 
UNIV_INTERN
 
232
 
242
233
ulint
243
234
row_get_mysql_key_number_for_index(
244
235
/*===============================*/
245
 
        const dict_index_t*     index);
 
236
        dict_index_t*   index);
246
237
/*************************************************************************
247
238
Does an update or delete of a row for MySQL. */
248
 
UNIV_INTERN
 
239
 
249
240
int
250
241
row_update_for_mysql(
251
242
/*=================*/
265
256
LOCK_X type.
266
257
Thus, this implements a 'mini-rollback' that releases the latest record
267
258
locks we set. */
268
 
UNIV_INTERN
 
259
 
269
260
int
270
261
row_unlock_for_mysql(
271
262
/*=================*/
279
270
/*************************************************************************
280
271
Creates an query graph node of 'update' type to be used in the MySQL
281
272
interface. */
282
 
UNIV_INTERN
 
273
 
283
274
upd_node_t*
284
275
row_create_update_node_for_mysql(
285
276
/*=============================*/
288
279
        mem_heap_t*     heap);  /* in: mem heap from which allocated */
289
280
/**************************************************************************
290
281
Does a cascaded delete or set null in a foreign key operation. */
291
 
UNIV_INTERN
 
282
 
292
283
ulint
293
284
row_update_cascade_for_mysql(
294
285
/*=========================*/
300
291
/*************************************************************************
301
292
Locks the data dictionary exclusively for performing a table create or other
302
293
data dictionary modification operation. */
303
 
UNIV_INTERN
 
294
 
304
295
void
305
296
row_mysql_lock_data_dictionary(
306
297
/*===========================*/
307
298
        trx_t*  trx);   /* in: transaction */
308
299
/*************************************************************************
309
300
Unlocks the data dictionary exclusive lock. */
310
 
UNIV_INTERN
 
301
 
311
302
void
312
303
row_mysql_unlock_data_dictionary(
313
304
/*=============================*/
315
306
/*************************************************************************
316
307
Locks the data dictionary in shared mode from modifications, for performing
317
308
foreign key check, rollback, or other operation invisible to MySQL. */
318
 
UNIV_INTERN
 
309
 
319
310
void
320
311
row_mysql_freeze_data_dictionary(
321
312
/*=============================*/
322
313
        trx_t*  trx);   /* in: transaction */
323
314
/*************************************************************************
324
315
Unlocks the data dictionary shared lock. */
325
 
UNIV_INTERN
 
316
 
326
317
void
327
318
row_mysql_unfreeze_data_dictionary(
328
319
/*===============================*/
329
320
        trx_t*  trx);   /* in: transaction */
330
 
#ifndef UNIV_HOTBACKUP
331
321
/*************************************************************************
332
 
Creates a table for MySQL. If the name of the table ends in
 
322
Drops a table for MySQL. If the name of the table ends in
333
323
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
334
324
"innodb_table_monitor", then this will also start the printing of monitor
335
325
output by the master thread. If the table name ends in "innodb_mem_validate",
336
326
InnoDB will try to invoke mem_validate(). */
337
 
UNIV_INTERN
 
327
 
338
328
int
339
329
row_create_table_for_mysql(
340
330
/*=======================*/
345
335
Does an index creation operation for MySQL. TODO: currently failure
346
336
to create an index results in dropping the whole table! This is no problem
347
337
currently as all indexes must be created at the same time as the table. */
348
 
UNIV_INTERN
 
338
 
349
339
int
350
340
row_create_index_for_mysql(
351
341
/*=======================*/
365
355
Each foreign key constraint must be accompanied with indexes in
366
356
bot participating tables. The indexes are allowed to contain more
367
357
fields than mentioned in the constraint. */
368
 
UNIV_INTERN
 
358
 
369
359
int
370
360
row_table_add_foreign_constraints(
371
361
/*==============================*/
387
377
The master thread in srv0srv.c calls this regularly to drop tables which
388
378
we must drop in background after queries to them have ended. Such lazy
389
379
dropping of tables is needed in ALTER TABLE on Unix. */
390
 
UNIV_INTERN
 
380
 
391
381
ulint
392
382
row_drop_tables_for_mysql_in_background(void);
393
383
/*=========================================*/
396
386
/*************************************************************************
397
387
Get the background drop list length. NOTE: the caller must own the kernel
398
388
mutex! */
399
 
UNIV_INTERN
 
389
 
400
390
ulint
401
391
row_get_background_drop_list_len_low(void);
402
392
/*======================================*/
403
393
                                        /* out: how many tables in list */
404
394
/*************************************************************************
405
395
Truncates a table for MySQL. */
406
 
UNIV_INTERN
 
396
 
407
397
int
408
398
row_truncate_table_for_mysql(
409
399
/*=========================*/
415
405
one of "innodb_monitor", "innodb_lock_monitor", "innodb_tablespace_monitor",
416
406
"innodb_table_monitor", then this will also stop the printing of monitor
417
407
output by the master thread. */
418
 
UNIV_INTERN
 
408
 
419
409
int
420
410
row_drop_table_for_mysql(
421
411
/*=====================*/
425
415
        ibool           drop_db);/* in: TRUE=dropping whole database */
426
416
 
427
417
/*************************************************************************
428
 
Drops a table for MySQL but does not commit the transaction.  If the
429
 
name of the dropped table ends in one of "innodb_monitor",
430
 
"innodb_lock_monitor", "innodb_tablespace_monitor",
431
 
"innodb_table_monitor", then this will also stop the printing of
432
 
monitor output by the master thread. */
433
 
UNIV_INTERN
434
 
int
435
 
row_drop_table_for_mysql_no_commit(
436
 
/*===============================*/
437
 
                                /* out: error code or DB_SUCCESS */
438
 
        const char*     name,   /* in: table name */
439
 
        trx_t*          trx,    /* in: transaction handle */
440
 
        ibool           drop_db);/* in: TRUE=dropping whole database */
441
 
/*************************************************************************
442
418
Discards the tablespace of a table which stored in an .ibd file. Discarding
443
419
means that this function deletes the .ibd file and assigns a new table id for
444
420
the table. Also the flag table->ibd_file_missing is set TRUE. */
445
 
UNIV_INTERN
 
421
 
446
422
int
447
423
row_discard_tablespace_for_mysql(
448
424
/*=============================*/
452
428
/*********************************************************************
453
429
Imports a tablespace. The space id in the .ibd file must match the space id
454
430
of the table in the data dictionary. */
455
 
UNIV_INTERN
 
431
 
456
432
int
457
433
row_import_tablespace_for_mysql(
458
434
/*============================*/
461
437
        trx_t*          trx);   /* in: transaction handle */
462
438
/*************************************************************************
463
439
Drops a database for MySQL. */
464
 
UNIV_INTERN
 
440
 
465
441
int
466
442
row_drop_database_for_mysql(
467
443
/*========================*/
470
446
        trx_t*          trx);   /* in: transaction handle */
471
447
/*************************************************************************
472
448
Renames a table for MySQL. */
473
 
UNIV_INTERN
474
 
ulint
 
449
 
 
450
int
475
451
row_rename_table_for_mysql(
476
452
/*=======================*/
477
453
                                        /* out: error code or DB_SUCCESS */
478
454
        const char*     old_name,       /* in: old table name */
479
455
        const char*     new_name,       /* in: new table name */
480
 
        trx_t*          trx,            /* in: transaction handle */
481
 
        ibool           commit);        /* in: if TRUE then commit trx */
 
456
        trx_t*          trx);           /* in: transaction handle */
482
457
/*************************************************************************
483
458
Checks a table for corruption. */
484
 
UNIV_INTERN
 
459
 
485
460
ulint
486
461
row_check_table_for_mysql(
487
462
/*======================*/
488
463
                                        /* out: DB_ERROR or DB_SUCCESS */
489
464
        row_prebuilt_t* prebuilt);      /* in: prebuilt struct in MySQL
490
465
                                        handle */
491
 
#endif /* !UNIV_HOTBACKUP */
492
 
 
493
 
/*************************************************************************
494
 
Determines if a table is a magic monitor table. */
495
 
UNIV_INTERN
496
 
ibool
497
 
row_is_magic_monitor_table(
498
 
/*=======================*/
499
 
                                        /* out: TRUE if monitor table */
500
 
        const char*     table_name);    /* in: name of the table, in the
501
 
                                        form database/table_name */
502
466
 
503
467
/* A struct describing a place for an individual column in the MySQL
504
468
row format which is presented to the table handler in ha_innobase.
511
475
        ulint   rec_field_no;           /* field number of the column in an
512
476
                                        Innobase record in the current index;
513
477
                                        not defined if template_type is
514
 
                                        ROW_MYSQL_WHOLE_ROW */
 
478
                                        ROW_DRIZZLE_WHOLE_ROW */
515
479
        ulint   mysql_col_offset;       /* offset of the column in the MySQL
516
480
                                        row format */
517
481
        ulint   mysql_col_len;          /* length of the column in the MySQL
525
489
        ulint   mysql_type;             /* MySQL type code; this is always
526
490
                                        < 256 */
527
491
        ulint   mysql_length_bytes;     /* if mysql_type
528
 
                                        == DATA_MYSQL_TRUE_VARCHAR, this tells
 
492
                                        == DATA_DRIZZLE_TRUE_VARCHAR, this tells
529
493
                                        whether we should use 1 or 2 bytes to
530
494
                                        store the MySQL true VARCHAR data
531
495
                                        length at the start of row in the MySQL
543
507
                                        it is an unsigned integer type */
544
508
};
545
509
 
546
 
#define MYSQL_FETCH_CACHE_SIZE          8
 
510
#define DRIZZLE_FETCH_CACHE_SIZE                8
547
511
/* After fetching this many rows, we start caching them in fetch_cache */
548
 
#define MYSQL_FETCH_CACHE_THRESHOLD     4
 
512
#define DRIZZLE_FETCH_CACHE_THRESHOLD   4
549
513
 
550
514
#define ROW_PREBUILT_ALLOCATED  78540783
551
515
#define ROW_PREBUILT_FREED      26423527
557
521
 
558
522
struct row_prebuilt_struct {
559
523
        ulint           magic_n;        /* this magic number is set to
560
 
                                        ROW_PREBUILT_ALLOCATED when created,
561
 
                                        or ROW_PREBUILT_FREED when the
562
 
                                        struct has been freed */
 
524
                                        ROW_PREBUILT_ALLOCATED when created
 
525
                                        and to ROW_PREBUILT_FREED when the
 
526
                                        struct has been freed; used in
 
527
                                        debugging */
563
528
        dict_table_t*   table;          /* Innobase table handle */
564
529
        trx_t*          trx;            /* current transaction handle */
565
530
        ibool           sql_stat_start; /* TRUE when we start processing of
592
557
                                        unique search from a clustered index,
593
558
                                        because HANDLER allows NEXT and PREV
594
559
                                        in such a situation */
595
 
        ulint           template_type;  /* ROW_MYSQL_WHOLE_ROW,
596
 
                                        ROW_MYSQL_REC_FIELDS,
597
 
                                        ROW_MYSQL_DUMMY_TEMPLATE, or
598
 
                                        ROW_MYSQL_NO_TEMPLATE */
 
560
        ulint           template_type;  /* ROW_DRIZZLE_WHOLE_ROW,
 
561
                                        ROW_DRIZZLE_REC_FIELDS,
 
562
                                        ROW_DRIZZLE_DUMMY_TEMPLATE, or
 
563
                                        ROW_DRIZZLE_NO_TEMPLATE */
599
564
        ulint           n_template;     /* number of elements in the
600
565
                                        template */
601
566
        ulint           null_bitmap_len;/* number of bytes in the SQL NULL
688
653
        ulint           n_rows_fetched; /* number of rows fetched after
689
654
                                        positioning the current cursor */
690
655
        ulint           fetch_direction;/* ROW_SEL_NEXT or ROW_SEL_PREV */
691
 
        byte*           fetch_cache[MYSQL_FETCH_CACHE_SIZE];
 
656
        byte*           fetch_cache[DRIZZLE_FETCH_CACHE_SIZE];
692
657
                                        /* a cache for fetched rows if we
693
658
                                        fetch many rows from the same cursor:
694
659
                                        it saves CPU time to fetch them in a
710
675
                                        to this heap */
711
676
        mem_heap_t*     old_vers_heap;  /* memory heap where a previous
712
677
                                        version is built in consistent read */
713
 
        ib_uint64_t     last_value;     /* last value of AUTO-INC interval */
714
 
        UT_LIST_NODE_T(row_prebuilt_t)  prebuilts;
715
 
                                        /* list node of table->prebuilts */
716
 
        index_cond_func_t idx_cond_func;/* Index Condition Pushdown function,
 
678
        uint64_t        last_value;     /* last value of AUTO-INC interval */
 
679
 
 
680
        index_cond_func_t idx_cond_func;/* Index Condition Pushdown function,
717
681
                                        or NULL if there is none set */
718
 
        void*           idx_cond_func_arg;/* ICP function  argument */
 
682
        void*           idx_cond_func_arg;/* ICP function  argument */
719
683
        ulint           n_index_fields; /* Number of fields at the start of
720
684
                                        mysql_template. Valid only when using
721
685
                                        ICP. */
725
689
 
726
690
#define ROW_PREBUILT_FETCH_MAGIC_N      465765687
727
691
 
728
 
#define ROW_MYSQL_WHOLE_ROW     0
729
 
#define ROW_MYSQL_REC_FIELDS    1
730
 
#define ROW_MYSQL_NO_TEMPLATE   2
731
 
#define ROW_MYSQL_DUMMY_TEMPLATE 3      /* dummy template used in
 
692
#define ROW_DRIZZLE_WHOLE_ROW   0
 
693
#define ROW_DRIZZLE_REC_FIELDS  1
 
694
#define ROW_DRIZZLE_NO_TEMPLATE 2
 
695
#define ROW_DRIZZLE_DUMMY_TEMPLATE 3    /* dummy template used in
732
696
                                        row_scan_and_check_index */
733
697
 
734
698
/* Values for hint_need_to_fetch_extra_cols */