162
173
/** The insert buffer control structure */
163
174
UNIV_INTERN ibuf_t* ibuf = NULL;
176
/** Counter for ibuf_should_try() */
165
177
UNIV_INTERN ulint ibuf_flush_count = 0;
167
179
#ifdef UNIV_IBUF_COUNT_DEBUG
168
/* Dimensions for the ibuf_count array */
180
/** Number of tablespaces in the ibuf_counts array */
169
181
#define IBUF_COUNT_N_SPACES 4
182
/** Number of pages within each tablespace in the ibuf_counts array */
170
183
#define IBUF_COUNT_N_PAGES 130000
172
/* Buffered entry counts for file pages, used in debugging */
185
/** Buffered entry counts for file pages, used in debugging */
173
186
static ulint ibuf_counts[IBUF_COUNT_N_SPACES][IBUF_COUNT_N_PAGES];
175
/**********************************************************************
188
/******************************************************************//**
176
189
Checks that the indexes to ibuf_counts[][] are within limits. */
179
192
ibuf_count_check(
180
193
/*=============*/
181
ulint space_id, /* in: space identifier */
182
ulint page_no) /* in: page number */
194
ulint space_id, /*!< in: space identifier */
195
ulint page_no) /*!< in: page number */
184
197
if (space_id < IBUF_COUNT_N_SPACES && page_no < IBUF_COUNT_N_PAGES) {
199
/* The start address for an insert buffer bitmap page bitmap */
200
#define IBUF_BITMAP PAGE_DATA
202
/* Offsets in bits for the bits describing a single page in the bitmap */
203
#define IBUF_BITMAP_FREE 0
204
#define IBUF_BITMAP_BUFFERED 2
205
#define IBUF_BITMAP_IBUF 3 /* TRUE if page is a part of the ibuf
206
tree, excluding the root page, or is
207
in the free list of the ibuf */
209
/* Number of bits describing a single page */
210
#define IBUF_BITS_PER_PAGE 4
211
#if IBUF_BITS_PER_PAGE % 2
212
# error "IBUF_BITS_PER_PAGE must be an even number!"
215
/* The mutex used to block pessimistic inserts to ibuf trees */
212
/** @name Offsets to the per-page bits in the insert buffer bitmap */
214
#define IBUF_BITMAP_FREE 0 /*!< Bits indicating the
215
amount of free space */
216
#define IBUF_BITMAP_BUFFERED 2 /*!< TRUE if there are buffered
217
changes for the page */
218
#define IBUF_BITMAP_IBUF 3 /*!< TRUE if page is a part of
219
the ibuf tree, excluding the
220
root page, or is in the free
224
/** The mutex used to block pessimistic inserts to ibuf trees */
216
225
static mutex_t ibuf_pessimistic_insert_mutex;
218
/* The mutex protecting the insert buffer structs */
227
/** The mutex protecting the insert buffer structs */
219
228
static mutex_t ibuf_mutex;
221
/* The mutex protecting the insert buffer bitmaps */
230
/** The mutex protecting the insert buffer bitmaps */
222
231
static mutex_t ibuf_bitmap_mutex;
224
/* The area in pages from which contract looks for page numbers for merge */
233
/** The area in pages from which contract looks for page numbers for merge */
225
234
#define IBUF_MERGE_AREA 8
227
/* Inside the merge area, pages which have at most 1 per this number less
236
/** Inside the merge area, pages which have at most 1 per this number less
228
237
buffered entries compared to maximum volume that can buffered for a single
229
238
page are merged along with the page whose buffer became full */
230
239
#define IBUF_MERGE_THRESHOLD 4
232
/* In ibuf_contract at most this number of pages is read to memory in one
241
/** In ibuf_contract at most this number of pages is read to memory in one
233
242
batch, in order to merge the entries for them in the insert buffer */
234
243
#define IBUF_MAX_N_PAGES_MERGED IBUF_MERGE_AREA
236
/* If the combined size of the ibuf trees exceeds ibuf->max_size by this
245
/** If the combined size of the ibuf trees exceeds ibuf->max_size by this
237
246
many pages, we start to contract it in connection to inserts there, using
238
247
non-synchronous contract */
239
248
#define IBUF_CONTRACT_ON_INSERT_NON_SYNC 0
241
/* Same as above, but use synchronous contract */
250
/** If the combined size of the ibuf trees exceeds ibuf->max_size by this
251
many pages, we start to contract it in connection to inserts there, using
252
synchronous contract */
242
253
#define IBUF_CONTRACT_ON_INSERT_SYNC 5
244
/* Same as above, but no insert is done, only contract is called */
255
/** If the combined size of the ibuf trees exceeds ibuf->max_size by
256
this many pages, we start to contract it synchronous contract, but do
245
258
#define IBUF_CONTRACT_DO_NOT_INSERT 10
247
260
/* TODO: how to cope with drop table if there are records in the insert
287
/**********************************************************************
300
/******************************************************************//**
288
301
Returns TRUE if the current OS thread is performing an insert buffer
304
For instance, a read-ahead of non-ibuf pages is forbidden by threads
305
that are executing an insert buffer routine.
306
@return TRUE if inside an insert buffer routine */
292
309
ibuf_inside(void)
293
310
/*=============*/
294
/* out: TRUE if inside an insert buffer routine: for instance,
295
a read-ahead of non-ibuf pages is then forbidden */
297
312
return(*thr_local_get_in_ibuf_field());
300
/**********************************************************************
301
Gets the ibuf header page and x-latches it. */
315
/******************************************************************//**
316
Gets the ibuf header page and x-latches it.
317
@return insert buffer header page */
304
320
ibuf_header_page_get(
305
321
/*=================*/
306
/* out: insert buffer header page */
307
mtr_t* mtr) /* in: mtr */
322
mtr_t* mtr) /*!< in: mtr */
309
324
buf_block_t* block;
343
358
#ifdef UNIV_IBUF_COUNT_DEBUG
344
/**********************************************************************
345
Gets the ibuf count for a given page. */
359
/******************************************************************//**
360
Gets the ibuf count for a given page.
361
@return number of entries in the insert buffer currently buffered for
350
/* out: number of entries in the insert buffer
351
currently buffered for this page */
352
ulint space, /* in: space id */
353
ulint page_no)/* in: page number */
367
ulint space, /*!< in: space id */
368
ulint page_no)/*!< in: page number */
355
370
ibuf_count_check(space, page_no);
357
372
return(ibuf_counts[space][page_no]);
360
/**********************************************************************
375
/******************************************************************//**
361
376
Sets the ibuf count for a given page. */
366
ulint space, /* in: space id */
367
ulint page_no,/* in: page number */
368
ulint val) /* in: value to set */
381
ulint space, /*!< in: space id */
382
ulint page_no,/*!< in: page number */
383
ulint val) /*!< in: value to set */
370
385
ibuf_count_check(space, page_no);
371
386
ut_a(val < UNIV_PAGE_SIZE);
377
/**********************************************************************
392
/******************************************************************//**
378
393
Updates the size information of the ibuf, assuming the segment size has not
382
397
ibuf_size_update(
383
398
/*=============*/
384
const page_t* root, /* in: ibuf tree root */
385
mtr_t* mtr) /* in: mtr */
399
const page_t* root, /*!< in: ibuf tree root */
400
mtr_t* mtr) /*!< in: mtr */
387
402
ut_ad(mutex_own(&ibuf_mutex));
493
508
ibuf->index = dict_table_get_first_index(table);
496
/*************************************************************************
510
#endif /* !UNIV_HOTBACKUP */
511
/*********************************************************************//**
497
512
Initializes an ibuf bitmap page. */
500
515
ibuf_bitmap_page_init(
501
516
/*==================*/
502
buf_block_t* block, /* in: bitmap page */
503
mtr_t* mtr) /* in: mtr */
517
buf_block_t* block, /*!< in: bitmap page */
518
mtr_t* mtr) /*!< in: mtr */
506
521
ulint byte_offset;
525
540
/* The remaining area (up to the page trailer) is uninitialized. */
542
#ifndef UNIV_HOTBACKUP
527
543
mlog_write_initial_log_record(page, MLOG_IBUF_BITMAP_INIT, mtr);
544
#endif /* !UNIV_HOTBACKUP */
530
/*************************************************************************
531
Parses a redo log record of an ibuf bitmap page init. */
547
/*********************************************************************//**
548
Parses a redo log record of an ibuf bitmap page init.
549
@return end of log record or NULL */
534
552
ibuf_parse_bitmap_init(
535
553
/*===================*/
536
/* out: end of log record or NULL */
537
byte* ptr, /* in: buffer */
538
byte* end_ptr __attribute__((unused)), /* in: buffer end */
539
buf_block_t* block, /* in: block or NULL */
540
mtr_t* mtr) /* in: mtr or NULL */
554
byte* ptr, /*!< in: buffer */
555
byte* end_ptr __attribute__((unused)), /*!< in: buffer end */
556
buf_block_t* block, /*!< in: block or NULL */
557
mtr_t* mtr) /*!< in: mtr or NULL */
542
559
ut_ad(ptr && end_ptr);
551
/************************************************************************
552
Gets the desired bits for a given page from a bitmap page. */
567
#ifndef UNIV_HOTBACKUP
568
/********************************************************************//**
569
Gets the desired bits for a given page from a bitmap page.
570
@return value of bits */
555
573
ibuf_bitmap_page_get_bits(
556
574
/*======================*/
557
/* out: value of bits */
558
const page_t* page, /* in: bitmap page */
559
ulint page_no,/* in: page whose bits to get */
560
ulint zip_size,/* in: compressed page size in bytes;
575
const page_t* page, /*!< in: bitmap page */
576
ulint page_no,/*!< in: page whose bits to get */
577
ulint zip_size,/*!< in: compressed page size in bytes;
561
578
0 for uncompressed pages */
562
ulint bit, /* in: IBUF_BITMAP_FREE,
579
ulint bit, /*!< in: IBUF_BITMAP_FREE,
563
580
IBUF_BITMAP_BUFFERED, ... */
564
581
mtr_t* mtr __attribute__((unused)))
565
/* in: mtr containing an
582
/*!< in: mtr containing an
566
583
x-latch to the bitmap page */
568
585
ulint byte_offset;
606
/************************************************************************
623
/********************************************************************//**
607
624
Sets the desired bit for a given page in a bitmap page. */
610
627
ibuf_bitmap_page_set_bits(
611
628
/*======================*/
612
page_t* page, /* in: bitmap page */
613
ulint page_no,/* in: page whose bits to set */
614
ulint zip_size,/* in: compressed page size in bytes;
629
page_t* page, /*!< in: bitmap page */
630
ulint page_no,/*!< in: page whose bits to set */
631
ulint zip_size,/*!< in: compressed page size in bytes;
615
632
0 for uncompressed pages */
616
ulint bit, /* in: IBUF_BITMAP_FREE, IBUF_BITMAP_BUFFERED, ... */
617
ulint val, /* in: value to set */
618
mtr_t* mtr) /* in: mtr containing an x-latch to the bitmap page */
633
ulint bit, /*!< in: IBUF_BITMAP_FREE, IBUF_BITMAP_BUFFERED, ... */
634
ulint val, /*!< in: value to set */
635
mtr_t* mtr) /*!< in: mtr containing an x-latch to the bitmap page */
620
637
ulint byte_offset;
621
638
ulint bit_offset;
662
679
MLOG_1BYTE, mtr);
665
/************************************************************************
666
Calculates the bitmap page number for a given page number. */
682
/********************************************************************//**
683
Calculates the bitmap page number for a given page number.
684
@return the bitmap page number where the file page is mapped */
669
687
ibuf_bitmap_page_no_calc(
670
688
/*=====================*/
671
/* out: the bitmap page number where
672
the file page is mapped */
673
ulint zip_size, /* in: compressed page size in bytes;
689
ulint zip_size, /*!< in: compressed page size in bytes;
674
690
0 for uncompressed pages */
675
ulint page_no) /* in: tablespace page number */
691
ulint page_no) /*!< in: tablespace page number */
677
693
ut_ad(ut_is_2pow(zip_size));
688
/************************************************************************
704
/********************************************************************//**
689
705
Gets the ibuf bitmap page where the bits describing a given file page are
707
@return bitmap page where the file page is mapped, that is, the bitmap
708
page containing the descriptor bits for the file page; the bitmap page
693
712
ibuf_bitmap_get_map_page(
694
713
/*=====================*/
695
/* out: bitmap page where the file page is mapped,
696
that is, the bitmap page containing the descriptor
697
bits for the file page; the bitmap page is
699
ulint space, /* in: space id of the file page */
700
ulint page_no,/* in: page number of the file page */
701
ulint zip_size,/* in: compressed page size in bytes;
714
ulint space, /*!< in: space id of the file page */
715
ulint page_no,/*!< in: page number of the file page */
716
ulint zip_size,/*!< in: compressed page size in bytes;
702
717
0 for uncompressed pages */
703
mtr_t* mtr) /* in: mtr */
718
mtr_t* mtr) /*!< in: mtr */
705
720
buf_block_t* block;
722
737
ibuf_set_free_bits_low(
723
738
/*===================*/
724
ulint zip_size,/* in: compressed page size in bytes;
739
ulint zip_size,/*!< in: compressed page size in bytes;
725
740
0 for uncompressed pages */
726
const buf_block_t* block, /* in: index page; free bits are set if
741
const buf_block_t* block, /*!< in: index page; free bits are set if
727
742
the index is non-clustered and page
729
ulint val, /* in: value to set: < 4 */
730
mtr_t* mtr) /* in/out: mtr */
744
ulint val, /*!< in: value to set: < 4 */
745
mtr_t* mtr) /*!< in/out: mtr */
732
747
page_t* bitmap_page;
765
780
ibuf_set_free_bits_func(
766
781
/*====================*/
767
buf_block_t* block, /* in: index page of a non-clustered index;
782
buf_block_t* block, /*!< in: index page of a non-clustered index;
768
783
free bit is reset if page level is 0 */
769
784
#ifdef UNIV_IBUF_DEBUG
770
ulint max_val,/* in: ULINT_UNDEFINED or a maximum
785
ulint max_val,/*!< in: ULINT_UNDEFINED or a maximum
771
786
value which the bits must have before
772
787
setting; this is for debugging */
773
788
#endif /* UNIV_IBUF_DEBUG */
774
ulint val) /* in: value to set: < 4 */
789
ulint val) /*!< in: value to set: < 4 */
839
854
ibuf_reset_free_bits(
840
855
/*=================*/
841
buf_block_t* block) /* in: index page; free bits are set to 0
856
buf_block_t* block) /*!< in: index page; free bits are set to 0
842
857
if the index is a non-clustered
843
858
non-unique, and page level is 0 */
845
860
ibuf_set_free_bits(block, 0, ULINT_UNDEFINED);
848
/**************************************************************************
863
/**********************************************************************//**
849
864
Updates the free bits for an uncompressed page to reflect the present
850
865
state. Does this in the mtr given, which means that the latching
851
866
order rules virtually prevent any further operations for this OS
858
873
ibuf_update_free_bits_low(
859
874
/*======================*/
860
const buf_block_t* block, /* in: index page */
861
ulint max_ins_size, /* in: value of
875
const buf_block_t* block, /*!< in: index page */
876
ulint max_ins_size, /*!< in: value of
862
877
maximum insert size
863
878
with reorganize before
864
879
the latest operation
865
880
performed to the page */
866
mtr_t* mtr) /* in/out: mtr */
881
mtr_t* mtr) /*!< in/out: mtr */
940
955
ibuf_update_free_bits_for_two_pages_low(
941
956
/*====================================*/
942
ulint zip_size,/* in: compressed page size in bytes;
957
ulint zip_size,/*!< in: compressed page size in bytes;
943
958
0 for uncompressed pages */
944
buf_block_t* block1, /* in: index page */
945
buf_block_t* block2, /* in: index page */
946
mtr_t* mtr) /* in: mtr */
959
buf_block_t* block1, /*!< in: index page */
960
buf_block_t* block2, /*!< in: index page */
961
mtr_t* mtr) /*!< in: mtr */
964
979
mutex_exit(&ibuf_bitmap_mutex);
967
/**************************************************************************
968
Returns TRUE if the page is one of the fixed address ibuf pages. */
982
/**********************************************************************//**
983
Returns TRUE if the page is one of the fixed address ibuf pages.
984
@return TRUE if a fixed address ibuf i/o page */
971
987
ibuf_fixed_addr_page(
972
988
/*=================*/
973
/* out: TRUE if a fixed address ibuf i/o page */
974
ulint space, /* in: space id */
975
ulint zip_size,/* in: compressed page size in bytes;
989
ulint space, /*!< in: space id */
990
ulint zip_size,/*!< in: compressed page size in bytes;
976
991
0 for uncompressed pages */
977
ulint page_no)/* in: page number */
992
ulint page_no)/*!< in: page number */
979
994
return((space == IBUF_SPACE_ID && page_no == IBUF_TREE_ROOT_PAGE_NO)
980
995
|| ibuf_bitmap_page(zip_size, page_no));
983
/***************************************************************************
998
/***********************************************************************//**
984
999
Checks if a page is a level 2 or 3 page in the ibuf hierarchy of pages.
985
Must not be called when recv_no_ibuf_operations==TRUE. */
1000
Must not be called when recv_no_ibuf_operations==TRUE.
1001
@return TRUE if level 2 or level 3 page */
990
/* out: TRUE if level 2 or level 3 page */
991
ulint space, /* in: space id */
992
ulint zip_size,/* in: compressed page size in bytes, or 0 */
993
ulint page_no,/* in: page number */
994
mtr_t* mtr) /* in: mtr which will contain an x-latch to the
1006
ulint space, /*!< in: space id */
1007
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
1008
ulint page_no,/*!< in: page number */
1009
mtr_t* mtr) /*!< in: mtr which will contain an x-latch to the
995
1010
bitmap page if the page is not one of the fixed
996
1011
address ibuf pages, or NULL, in which case a new
997
1012
transaction is created. */
1128
/************************************************************************
1143
/********************************************************************//**
1129
1144
Add a column to the dummy index */
1132
1147
ibuf_dummy_index_add_col(
1133
1148
/*=====================*/
1134
dict_index_t* index, /* in: dummy index */
1135
const dtype_t* type, /* in: the data type of the column */
1136
ulint len) /* in: length of the column */
1149
dict_index_t* index, /*!< in: dummy index */
1150
const dtype_t* type, /*!< in: the data type of the column */
1151
ulint len) /*!< in: length of the column */
1138
1153
ulint i = index->table->n_def;
1139
1154
dict_mem_table_add_col(index->table, NULL, NULL,
1143
1158
dict_index_add_col(index, index->table,
1144
1159
dict_table_get_nth_col(index->table, i), len);
1146
/************************************************************************
1147
Deallocates a dummy index for inserting a record to a non-clustered index.
1161
/********************************************************************//**
1162
Deallocates a dummy index for inserting a record to a non-clustered index. */
1151
1165
ibuf_dummy_index_free(
1152
1166
/*==================*/
1153
dict_index_t* index) /* in: dummy index */
1167
dict_index_t* index) /*!< in, own: dummy index */
1155
1169
dict_table_t* table = index->table;
1158
1172
dict_mem_table_free(table);
1161
/*************************************************************************
1175
/*********************************************************************//**
1162
1176
Builds the entry to insert into a non-clustered index when we have the
1163
corresponding record in an ibuf index. */
1177
corresponding record in an ibuf index.
1179
NOTE that as we copy pointers to fields in ibuf_rec, the caller must
1180
hold a latch to the ibuf_rec page as long as the entry is used!
1182
@return own: entry to insert to a non-clustered index */
1166
1185
ibuf_build_entry_pre_4_1_x(
1167
1186
/*=======================*/
1168
/* out, own: entry to insert to
1169
a non-clustered index; NOTE that
1170
as we copy pointers to fields in
1171
ibuf_rec, the caller must hold a
1172
latch to the ibuf_rec page as long
1173
as the entry is used! */
1174
const rec_t* ibuf_rec, /* in: record in an insert buffer */
1175
mem_heap_t* heap, /* in: heap where built */
1176
dict_index_t** pindex) /* out, own: dummy index that
1187
const rec_t* ibuf_rec, /*!< in: record in an insert buffer */
1188
mem_heap_t* heap, /*!< in: heap where built */
1189
dict_index_t** pindex) /*!< out, own: dummy index that
1177
1190
describes the entry */
1214
/*************************************************************************
1227
/*********************************************************************//**
1215
1228
Builds the entry to insert into a non-clustered index when we have the
1216
corresponding record in an ibuf index. */
1229
corresponding record in an ibuf index.
1231
NOTE that as we copy pointers to fields in ibuf_rec, the caller must
1232
hold a latch to the ibuf_rec page as long as the entry is used!
1234
@return own: entry to insert to a non-clustered index */
1219
1237
ibuf_build_entry_from_ibuf_rec(
1220
1238
/*===========================*/
1221
/* out, own: entry to insert to
1222
a non-clustered index; NOTE that
1223
as we copy pointers to fields in
1224
ibuf_rec, the caller must hold a
1225
latch to the ibuf_rec page as long
1226
as the entry is used! */
1227
const rec_t* ibuf_rec, /* in: record in an insert buffer */
1228
mem_heap_t* heap, /* in: heap where built */
1229
dict_index_t** pindex) /* out, own: dummy index that
1239
const rec_t* ibuf_rec, /*!< in: record in an insert buffer */
1240
mem_heap_t* heap, /*!< in: heap where built */
1241
dict_index_t** pindex) /*!< out, own: dummy index that
1230
1242
describes the entry */
1232
1244
dtuple_t* tuple;
1300
/************************************************************************
1312
/********************************************************************//**
1301
1313
Returns the space taken by a stored non-clustered index entry if converted to
1315
@return size of index record in bytes + an upper limit of the space
1316
taken in the page directory */
1305
1319
ibuf_rec_get_volume(
1306
1320
/*================*/
1307
/* out: size of index record in bytes
1308
+ an upper limit of the space taken in the
1310
const rec_t* ibuf_rec)/* in: ibuf record */
1321
const rec_t* ibuf_rec)/*!< in: ibuf record */
1313
1324
ibool new_format = FALSE;
1387
1402
+ page_dir_calc_reserved_space(1));
1390
/*************************************************************************
1405
/*********************************************************************//**
1391
1406
Builds the tuple to insert to an ibuf tree when we have an entry for a
1392
non-clustered index. */
1407
non-clustered index.
1409
NOTE that the original entry must be kept because we copy pointers to
1412
@return own: entry to insert into an ibuf index tree */
1395
1415
ibuf_entry_build(
1396
1416
/*=============*/
1397
/* out, own: entry to insert into an ibuf
1398
index tree; NOTE that the original entry
1399
must be kept because we copy pointers to its
1401
dict_index_t* index, /* in: non-clustered index */
1402
const dtuple_t* entry, /* in: entry for a non-clustered index */
1403
ulint space, /* in: space id */
1404
ulint page_no,/* in: index page number where entry should
1417
dict_index_t* index, /*!< in: non-clustered index */
1418
const dtuple_t* entry, /*!< in: entry for a non-clustered index */
1419
ulint space, /*!< in: space id */
1420
ulint page_no,/*!< in: index page number where entry should
1406
mem_heap_t* heap) /* in: heap into which to build */
1422
mem_heap_t* heap) /*!< in: heap into which to build */
1408
1424
dtuple_t* tuple;
1409
1425
dfield_t* field;
1530
/*************************************************************************
1546
/*********************************************************************//**
1531
1547
Builds a search tuple used to search buffered inserts for an index page.
1532
This is for < 4.1.x format records */
1548
This is for < 4.1.x format records
1549
@return own: search tuple */
1535
1552
ibuf_search_tuple_build(
1536
1553
/*====================*/
1537
/* out, own: search tuple */
1538
ulint space, /* in: space id */
1539
ulint page_no,/* in: index page number */
1540
mem_heap_t* heap) /* in: heap into which to build */
1554
ulint space, /*!< in: space id */
1555
ulint page_no,/*!< in: index page number */
1556
mem_heap_t* heap) /*!< in: heap into which to build */
1542
1558
dtuple_t* tuple;
1543
1559
dfield_t* field;
1567
/*************************************************************************
1583
/*********************************************************************//**
1568
1584
Builds a search tuple used to search buffered inserts for an index page.
1569
This is for >= 4.1.x format records. */
1585
This is for >= 4.1.x format records.
1586
@return own: search tuple */
1572
1589
ibuf_new_search_tuple_build(
1573
1590
/*========================*/
1574
/* out, own: search tuple */
1575
ulint space, /* in: space id */
1576
ulint page_no,/* in: index page number */
1577
mem_heap_t* heap) /* in: heap into which to build */
1591
ulint space, /*!< in: space id */
1592
ulint page_no,/*!< in: index page number */
1593
mem_heap_t* heap) /*!< in: heap into which to build */
1579
1595
dtuple_t* tuple;
1580
1596
dfield_t* field;
1622
/*************************************************************************
1638
/*********************************************************************//**
1623
1639
Checks if there are enough pages in the free list of the ibuf tree that we
1624
dare to start a pessimistic insert to the insert buffer. */
1640
dare to start a pessimistic insert to the insert buffer.
1641
@return TRUE if enough free pages in list */
1627
1644
ibuf_data_enough_free_for_insert(void)
1628
1645
/*==================================*/
1629
/* out: TRUE if enough free pages in list */
1631
1647
ut_ad(mutex_own(&ibuf_mutex));
1639
1655
return(ibuf->free_list_len >= (ibuf->size / 2) + 3 * ibuf->height);
1642
/*************************************************************************
1658
/*********************************************************************//**
1643
1659
Checks if there are enough pages in the free list of the ibuf tree that we
1644
should remove them and free to the file space management. */
1660
should remove them and free to the file space management.
1661
@return TRUE if enough free pages in list */
1647
1664
ibuf_data_too_much_free(void)
1648
1665
/*=========================*/
1649
/* out: TRUE if enough free pages in list */
1651
1667
ut_ad(mutex_own(&ibuf_mutex));
1653
1669
return(ibuf->free_list_len >= 3 + (ibuf->size / 2) + 3 * ibuf->height);
1656
/*************************************************************************
1672
/*********************************************************************//**
1657
1673
Allocates a new page from the ibuf file segment and adds it to the free
1675
@return DB_SUCCESS, or DB_STRONG_FAIL if no space left */
1661
1678
ibuf_add_free_page(void)
1662
1679
/*====================*/
1663
/* out: DB_SUCCESS, or DB_STRONG_FAIL
1667
1682
page_t* header_page;
1928
/*************************************************************************
1929
Reads page numbers from a leaf in an ibuf tree. */
1943
/*********************************************************************//**
1944
Reads page numbers from a leaf in an ibuf tree.
1945
@return a lower limit for the combined volume of records which will be
1932
1949
ibuf_get_merge_page_nos(
1933
1950
/*====================*/
1934
/* out: a lower limit for the combined volume
1935
of records which will be merged */
1936
ibool contract,/* in: TRUE if this function is called to
1951
ibool contract,/*!< in: TRUE if this function is called to
1937
1952
contract the tree, FALSE if this is called
1938
1953
when a single page becomes full and we look
1939
1954
if it pays to read also nearby pages */
1940
rec_t* rec, /* in: record from which we read up and down
1955
rec_t* rec, /*!< in: record from which we read up and down
1941
1956
in the chain of records */
1942
ulint* space_ids,/* in/out: space id's of the pages */
1943
ib_int64_t* space_versions,/* in/out: tablespace version
1957
ulint* space_ids,/*!< in/out: space id's of the pages */
1958
ib_int64_t* space_versions,/*!< in/out: tablespace version
1944
1959
timestamps; used to prevent reading in old
1945
1960
pages after DISCARD + IMPORT tablespace */
1946
ulint* page_nos,/* in/out: buffer for at least
1961
ulint* page_nos,/*!< in/out: buffer for at least
1947
1962
IBUF_MAX_N_PAGES_MERGED many page numbers;
1948
1963
the page numbers are in an ascending order */
1949
ulint* n_stored)/* out: number of page numbers stored to
1964
ulint* n_stored)/*!< out: number of page numbers stored to
1950
1965
page_nos in this function */
1952
1967
ulint prev_page_no;
2098
2113
return(sum_volumes);
2101
/*************************************************************************
2102
Contracts insert buffer trees by reading pages to the buffer pool. */
2116
/*********************************************************************//**
2117
Contracts insert buffer trees by reading pages to the buffer pool.
2118
@return a lower limit for the combined size in bytes of entries which
2119
will be merged from ibuf trees to the pages read, 0 if ibuf is
2105
2123
ibuf_contract_ext(
2106
2124
/*==============*/
2107
/* out: a lower limit for the combined size in bytes
2108
of entries which will be merged from ibuf trees to the
2109
pages read, 0 if ibuf is empty */
2110
ulint* n_pages,/* out: number of pages to which merged */
2111
ibool sync) /* in: TRUE if the caller wants to wait for the
2125
ulint* n_pages,/*!< out: number of pages to which merged */
2126
ibool sync) /*!< in: TRUE if the caller wants to wait for the
2112
2127
issued read with the highest tablespace address
2179
2194
return(sum_sizes + 1);
2182
/*************************************************************************
2183
Contracts insert buffer trees by reading pages to the buffer pool. */
2197
/*********************************************************************//**
2198
Contracts insert buffer trees by reading pages to the buffer pool.
2199
@return a lower limit for the combined size in bytes of entries which
2200
will be merged from ibuf trees to the pages read, 0 if ibuf is
2188
/* out: a lower limit for the combined size in bytes
2189
of entries which will be merged from ibuf trees to the
2190
pages read, 0 if ibuf is empty */
2191
ibool sync) /* in: TRUE if the caller wants to wait for the
2206
ibool sync) /*!< in: TRUE if the caller wants to wait for the
2192
2207
issued read with the highest tablespace address
2197
2212
return(ibuf_contract_ext(&n_pages, sync));
2200
/*************************************************************************
2201
Contracts insert buffer trees by reading pages to the buffer pool. */
2215
/*********************************************************************//**
2216
Contracts insert buffer trees by reading pages to the buffer pool.
2217
@return a lower limit for the combined size in bytes of entries which
2218
will be merged from ibuf trees to the pages read, 0 if ibuf is
2204
2222
ibuf_contract_for_n_pages(
2205
2223
/*======================*/
2206
/* out: a lower limit for the combined size in bytes
2207
of entries which will be merged from ibuf trees to the
2208
pages read, 0 if ibuf is empty */
2209
ibool sync, /* in: TRUE if the caller wants to wait for the
2224
ibool sync, /*!< in: TRUE if the caller wants to wait for the
2210
2225
issued read with the highest tablespace address
2212
ulint n_pages)/* in: try to read at least this many pages to
2227
ulint n_pages)/*!< in: try to read at least this many pages to
2213
2228
the buffer pool and merge the ibuf contents to
2276
/*************************************************************************
2291
/*********************************************************************//**
2277
2292
Gets an upper limit for the combined size of entries buffered in the insert
2278
buffer for a given page. */
2293
buffer for a given page.
2294
@return upper limit for the volume of buffered inserts for the index
2295
page, in bytes; UNIV_PAGE_SIZE, if the entries for the index page span
2296
several pages in the insert buffer */
2281
2299
ibuf_get_volume_buffered(
2282
2300
/*=====================*/
2283
/* out: upper limit for the volume of
2284
buffered inserts for the index page, in bytes;
2285
we may also return UNIV_PAGE_SIZE, if the
2286
entries for the index page span on several
2287
pages in the insert buffer */
2288
btr_pcur_t* pcur, /* in: pcur positioned at a place in an
2301
btr_pcur_t* pcur, /*!< in: pcur positioned at a place in an
2289
2302
insert buffer tree where we would insert an
2290
2303
entry for the index page whose number is
2291
2304
page_no, latch mode has to be BTR_MODIFY_PREV
2292
2305
or BTR_MODIFY_TREE */
2293
ulint space, /* in: space id */
2294
ulint page_no,/* in: page number of an index page */
2295
mtr_t* mtr) /* in: mtr */
2306
ulint space, /*!< in: space id */
2307
ulint page_no,/*!< in: page number of an index page */
2308
mtr_t* mtr) /*!< in: mtr */
2506
2519
fil_set_max_space_id_if_bigger(max_space_id);
2509
/*************************************************************************
2522
/*********************************************************************//**
2510
2523
Makes an index insert to the insert buffer, instead of directly to the disk
2511
page, if this is possible. */
2524
page, if this is possible.
2525
@return DB_SUCCESS, DB_FAIL, DB_STRONG_FAIL */
2514
2528
ibuf_insert_low(
2515
2529
/*============*/
2516
/* out: DB_SUCCESS, DB_FAIL, DB_STRONG_FAIL */
2517
ulint mode, /* in: BTR_MODIFY_PREV or BTR_MODIFY_TREE */
2518
const dtuple_t* entry, /* in: index entry to insert */
2530
ulint mode, /*!< in: BTR_MODIFY_PREV or BTR_MODIFY_TREE */
2531
const dtuple_t* entry, /*!< in: index entry to insert */
2519
2532
ulint entry_size,
2520
/* in: rec_get_converted_size(index, entry) */
2521
dict_index_t* index, /* in: index where to insert; must not be
2533
/*!< in: rec_get_converted_size(index, entry) */
2534
dict_index_t* index, /*!< in: index where to insert; must not be
2522
2535
unique or clustered */
2523
ulint space, /* in: space id where to insert */
2524
ulint zip_size,/* in: compressed page size in bytes, or 0 */
2525
ulint page_no,/* in: page number where to insert */
2526
que_thr_t* thr) /* in: query thread */
2536
ulint space, /*!< in: space id where to insert */
2537
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
2538
ulint page_no,/*!< in: page number where to insert */
2539
que_thr_t* thr) /*!< in: query thread */
2528
2541
big_rec_t* dummy_big_rec;
2529
2542
btr_pcur_t pcur;
2762
/*************************************************************************
2775
/*********************************************************************//**
2763
2776
Makes an index insert to the insert buffer, instead of directly to the disk
2764
2777
page, if this is possible. Does not do insert if the index is clustered
2779
@return TRUE if success */
2770
/* out: TRUE if success */
2771
const dtuple_t* entry, /* in: index entry to insert */
2772
dict_index_t* index, /* in: index where to insert */
2773
ulint space, /* in: space id where to insert */
2774
ulint zip_size,/* in: compressed page size in bytes, or 0 */
2775
ulint page_no,/* in: page number where to insert */
2776
que_thr_t* thr) /* in: query thread */
2784
const dtuple_t* entry, /*!< in: index entry to insert */
2785
dict_index_t* index, /*!< in: index where to insert */
2786
ulint space, /*!< in: space id where to insert */
2787
ulint zip_size,/*!< in: compressed page size in bytes, or 0 */
2788
ulint page_no,/*!< in: page number where to insert */
2789
que_thr_t* thr) /*!< in: query thread */
2779
2792
ulint entry_size;
2828
/************************************************************************
2841
/********************************************************************//**
2829
2842
During merge, inserts to an index page a secondary index entry extracted
2830
2843
from the insert buffer. */
2833
2846
ibuf_insert_to_index_page(
2834
2847
/*======================*/
2835
dtuple_t* entry, /* in: buffered entry to insert */
2836
buf_block_t* block, /* in/out: index page where the buffered entry
2848
dtuple_t* entry, /*!< in: buffered entry to insert */
2849
buf_block_t* block, /*!< in/out: index page where the buffered entry
2837
2850
should be placed */
2838
dict_index_t* index, /* in: record descriptor */
2839
mtr_t* mtr) /* in: mtr */
2851
dict_index_t* index, /*!< in: record descriptor */
2852
mtr_t* mtr) /*!< in: mtr */
2841
2854
page_cur_t page_cur;
2842
2855
ulint low_match;
2955
/*************************************************************************
2968
/*********************************************************************//**
2956
2969
Deletes from ibuf the record on which pcur is positioned. If we have to
2957
2970
resort to a pessimistic delete, this function commits mtr and closes
2972
@return TRUE if mtr was committed and pcur closed in this operation */
2961
2975
ibuf_delete_rec(
2962
2976
/*============*/
2963
/* out: TRUE if mtr was committed and pcur
2964
closed in this operation */
2965
ulint space, /* in: space id */
2966
ulint page_no,/* in: index page number where the record
2977
ulint space, /*!< in: space id */
2978
ulint page_no,/*!< in: index page number where the record
2967
2979
should belong */
2968
btr_pcur_t* pcur, /* in: pcur positioned on the record to
2980
btr_pcur_t* pcur, /*!< in: pcur positioned on the record to
2969
2981
delete, having latch mode BTR_MODIFY_LEAF */
2970
2982
const dtuple_t* search_tuple,
2971
/* in: search tuple for entries of page_no */
2972
mtr_t* mtr) /* in: mtr */
2983
/*!< in: search tuple for entries of page_no */
2984
mtr_t* mtr) /*!< in: mtr */
3080
3092
ibuf_merge_or_delete_for_page(
3081
3093
/*==========================*/
3082
buf_block_t* block, /* in: if page has been read from
3094
buf_block_t* block, /*!< in: if page has been read from
3083
3095
disk, pointer to the page x-latched,
3085
ulint space, /* in: space id of the index page */
3086
ulint page_no,/* in: page number of the index page */
3087
ulint zip_size,/* in: compressed page size in bytes,
3097
ulint space, /*!< in: space id of the index page */
3098
ulint page_no,/*!< in: page number of the index page */
3099
ulint zip_size,/*!< in: compressed page size in bytes,
3089
ibool update_ibuf_bitmap)/* in: normally this is set
3101
ibool update_ibuf_bitmap)/*!< in: normally this is set
3090
3102
to TRUE, but if we have deleted or are
3091
3103
deleting the tablespace, then we
3092
3104
naturally do not want to update a
3307
3319
keep the latch to the rec page until the
3308
3320
insertion is finished! */
3309
3321
dtuple_t* entry;
3322
trx_id_t max_trx_id;
3311
3323
dict_index_t* dummy_index;
3313
3325
max_trx_id = page_get_max_trx_id(page_align(rec));
3314
page_update_max_trx_id(block, page_zip, max_trx_id);
3326
page_update_max_trx_id(block, page_zip, max_trx_id,
3316
3329
entry = ibuf_build_entry_from_ibuf_rec(
3317
3330
rec, heap, &dummy_index);