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