Class: Innodb::Page::Index
- Inherits:
-
Innodb::Page
- Object
- Innodb::Page
- Innodb::Page::Index
- Defined in:
- lib/innodb/page/index.rb
Overview
A specialized class for handling INDEX pages, which contain a portion of the data from exactly one B+tree. These are typically the most common type of page in any database.
The basic structure of an INDEX page is: FIL header, INDEX header, FSEG header, fixed-width system records (infimum and supremum), user records (the actual data) which grow ascending by offset, free space, the page directory which grows descending by offset, and the FIL trailer.
Defined Under Namespace
Classes: RecordCursor
Constant Summary collapse
- RECORD_NEXT_SIZE =
The size (in bytes) of the "next" pointer in each record header.
2- RECORD_REDUNDANT_BITS_SIZE =
The size (in bytes) of the bit-packed fields in each record header for "redundant" record format.
4- RECORD_REDUNDANT_OFF1_OFFSET_MASK =
Masks for 1-byte record end-offsets within "redundant" records.
0x7f- RECORD_REDUNDANT_OFF1_NULL_MASK =
0x80- RECORD_REDUNDANT_OFF2_OFFSET_MASK =
Masks for 2-byte record end-offsets within "redundant" records.
0x3fff- RECORD_REDUNDANT_OFF2_NULL_MASK =
0x8000- RECORD_REDUNDANT_OFF2_EXTERN_MASK =
0x4000- RECORD_COMPACT_BITS_SIZE =
The size (in bytes) of the bit-packed fields in each record header for "compact" record format.
3- PAGE_DIRECTION =
Page direction values possible in the page_header's :direction field.
{ 1 => :left, # Inserts have been in descending order. 2 => :right, # Inserts have been in ascending order. 3 => :same_rec, # Unused by InnoDB. 4 => :same_page, # Unused by InnoDB. 5 => :no_direction, # Inserts have been in random order. }
- RECORD_TYPES =
Record types used in the :type field of the record header.
{ 0 => :conventional, # A normal user record in a leaf page. 1 => :node_pointer, # A node pointer in a non-leaf page. 2 => :infimum, # The system "infimum" record. 3 => :supremum, # The system "supremum" record. }
- RECORD_INFO_MIN_REC_FLAG =
This record is the minimum record at this level of the B-tree.
1- RECORD_INFO_DELETED_FLAG =
This record has been marked as deleted.
2- PAGE_DIR_SLOT_SIZE =
The size (in bytes) of the record pointers in each page directory slot.
2- PAGE_DIR_SLOT_MIN_N_OWNED =
The minimum number of records "owned" by each record with an entry in the page directory.
4- PAGE_DIR_SLOT_MAX_N_OWNED =
The maximum number of records "owned" by each record with an entry in the page directory.
8
Constants inherited from Innodb::Page
PAGE_TYPE, SPECIALIZED_CLASSES
Instance Attribute Summary collapse
-
#record_describer ⇒ Object
Returns the value of attribute record_describer.
Attributes inherited from Innodb::Page
Instance Method Summary collapse
-
#directory ⇒ Object
Return an array of row offsets for all entries in the page directory.
-
#directory_slots ⇒ Object
The number of directory slots in use.
-
#directory_space ⇒ Object
The amount of space consumed by the page directory.
-
#dump ⇒ Object
Dump the contents of a page for debugging purposes.
-
#each_child_page ⇒ Object
Iterate through all child pages of a node (non-leaf) page, which are stored as records with the child page number as the last field in the record.
- #each_garbage_record ⇒ Object
-
#each_record ⇒ Object
Iterate through all records.
-
#first_record ⇒ Object
Return the first record on this page.
-
#free_space ⇒ Object
Return the amount of free space in the page.
-
#fseg_header ⇒ Object
Return the "fseg" header.
-
#garbage_offset ⇒ Object
A helper function to return the offset to the first free record.
-
#header_space ⇒ Object
The amount of space consumed by the page header.
-
#infimum ⇒ Object
Return the infimum record on a page.
-
#level ⇒ Object
A helper function to return the page level from the "page" header, for easier access.
-
#make_record_description ⇒ Object
Return a set of field objects that describe the record.
-
#page_header ⇒ Object
Return the "index" header.
-
#pos_directory ⇒ Object
The position of the page directory, which starts at the "fil" trailer and grows backwards from there.
-
#pos_fseg_header ⇒ Object
Return the byte offset of the start of the "fseg" header, which immediately follows the "index" header.
-
#pos_index_header ⇒ Object
Return the byte offset of the start of the "index" page header, which immediately follows the "fil" header.
-
#pos_infimum ⇒ Object
Return the byte offset of the start of the "origin" of the infimum record, which is always the first record in the singly-linked record chain on any page, and represents a record with a "lower value than any possible user record".
-
#pos_records ⇒ Object
Return the byte offset of the start of records within the page (the position immediately after the page header).
-
#pos_supremum ⇒ Object
Return the byte offset of the start of the "origin" of the supremum record, which is always the last record in the singly-linked record chain on any page, and represents a record with a "higher value than any possible user record".
-
#pos_user_records ⇒ Object
Return the byte offset of the start of the user records in a page, which immediately follows the supremum record.
-
#record(offset) ⇒ Object
Parse and return a record at a given offset.
-
#record_bytes ⇒ Object
Return the actual bytes of the portion of the page which is used to store user records (eliminate the headers and trailer from the page).
-
#record_cursor(offset) ⇒ Object
Return a RecordCursor starting at offset.
-
#record_format ⇒ Object
Return (and cache) the record format provided by an external class.
-
#record_header(cursor) ⇒ Object
Return the header from a record.
-
#record_header_compact_additional(header, cursor) ⇒ Object
Read additional header information from a compact format record header.
-
#record_header_compact_null_bitmap(cursor) ⇒ Object
Return an array indicating which fields are null.
-
#record_header_compact_variable_lengths_and_externs(cursor, null_bitmap) ⇒ Object
Return an array containing an array of the length of each variable-length field and an array indicating which fields are stored externally.
-
#record_header_redundant_additional(header, cursor) ⇒ Object
Read additional header information from a redundant format record header.
-
#record_header_redundant_field_end_offsets(header, cursor) ⇒ Object
Read field end offsets from the provided cursor for each field as counted by n_fields.
-
#record_space ⇒ Object
Return the amount of space occupied by records in the page.
-
#records ⇒ Object
A helper function to return the number of records.
-
#root? ⇒ Boolean
A helper function to identify root index pages; they must be the only pages at their level.
-
#size_fseg_header ⇒ Object
The size of the "fseg" header.
-
#size_index_header ⇒ Object
The size of the "index" header.
-
#size_mum_record ⇒ Object
The size of the data from the supremum or infimum records.
-
#size_mum_record_header_additional ⇒ Object
The size of the additional data structures in the header of the system records, which is just 1 byte in redundant format to store the offset of the end of the field.
-
#size_record_header ⇒ Object
Return the size of the header for each record.
-
#supremum ⇒ Object
Return the supremum record on a page.
-
#system_record(offset) ⇒ Object
Parse and return simple fixed-format system records, such as InnoDB's internal infimum and supremum records.
-
#trailer_space ⇒ Object
The amount of space consumed by the trailers in the page.
-
#used_space ⇒ Object
Return the amount of used space in the page.
Methods inherited from Innodb::Page
#calculate_checksum, #checksum, #corrupt?, #cursor, #data, #fil_header, handle, #initialize, #inspect, #lsn, maybe_undefined, #next, #offset, parse, #pos_fil_header, #pos_fil_trailer, #pos_page_body, #prev, #size, #size_fil_header, #size_fil_trailer, #type
Constructor Details
This class inherits a constructor from Innodb::Page
Instance Attribute Details
#record_describer ⇒ Object
Returns the value of attribute record_describer.
13 14 15 |
# File 'lib/innodb/page/index.rb', line 13 def record_describer @record_describer end |
Instance Method Details
#directory ⇒ Object
Return an array of row offsets for all entries in the page directory.
648 649 650 651 652 653 654 655 656 657 658 659 |
# File 'lib/innodb/page/index.rb', line 648 def directory return @directory if @directory @directory = [] cursor(pos_directory).backward.name("page_directory") do |c| directory_slots.times do |n| @directory.push c.name("slot[#{n}]") { c.get_uint16 } end end @directory end |
#directory_slots ⇒ Object
The number of directory slots in use.
168 169 170 |
# File 'lib/innodb/page/index.rb', line 168 def directory_slots page_header[:n_dir_slots] end |
#directory_space ⇒ Object
The amount of space consumed by the page directory.
173 174 175 |
# File 'lib/innodb/page/index.rb', line 173 def directory_space directory_slots * PAGE_DIR_SLOT_SIZE end |
#dump ⇒ Object
Dump the contents of a page for debugging purposes.
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 |
# File 'lib/innodb/page/index.rb', line 662 def dump super puts "page header:" pp page_header puts puts "fseg header:" pp fseg_header puts puts "sizes:" puts " %-15s%5i" % [ "header", header_space ] puts " %-15s%5i" % [ "trailer", trailer_space ] puts " %-15s%5i" % [ "directory", directory_space ] puts " %-15s%5i" % [ "free", free_space ] puts " %-15s%5i" % [ "used", used_space ] puts " %-15s%5i" % [ "record", record_space ] puts " %-15s%5.2f" % [ "per record", (page_header[:n_recs] > 0) ? (record_space / page_header[:n_recs]) : 0 ] puts puts "page directory:" pp directory puts puts "system records:" pp infimum pp supremum puts puts "garbage records:" each_garbage_record do |rec| pp rec puts end puts puts "records:" each_record do |rec| pp rec puts end puts end |
#each_child_page ⇒ Object
Iterate through all child pages of a node (non-leaf) page, which are stored as records with the child page number as the last field in the record.
633 634 635 636 637 638 639 640 641 642 643 644 645 |
# File 'lib/innodb/page/index.rb', line 633 def each_child_page return nil if level == 0 unless block_given? return enum_for(:each_child_page) end each_record do |rec| yield rec[:child_page_number], rec[:key] end nil end |
#each_garbage_record ⇒ Object
612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 |
# File 'lib/innodb/page/index.rb', line 612 def each_garbage_record unless block_given? return enum_for(:each_garbage_record) end if garbage_offset == 0 return nil end c = record_cursor(garbage_offset) while rec = c.record yield rec end nil end |
#each_record ⇒ Object
Iterate through all records.
598 599 600 601 602 603 604 605 606 607 608 609 610 |
# File 'lib/innodb/page/index.rb', line 598 def each_record unless block_given? return enum_for(:each_record) end c = record_cursor(infimum[:next]) while rec = c.record yield rec end nil end |
#first_record ⇒ Object
Return the first record on this page.
592 593 594 595 |
# File 'lib/innodb/page/index.rb', line 592 def first_record first = record(infimum[:next]) first if first != supremum end |
#free_space ⇒ Object
Return the amount of free space in the page.
183 184 185 186 |
# File 'lib/innodb/page/index.rb', line 183 def free_space page_header[:garbage_size] + (size - size_fil_trailer - directory_space - page_header[:heap_top]) end |
#fseg_header ⇒ Object
Return the "fseg" header.
253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'lib/innodb/page/index.rb', line 253 def fseg_header @fseg_header ||= cursor(pos_fseg_header).name("fseg") do |c| { :leaf => c.name("fseg[leaf]") { Innodb::FsegEntry.get_inode(@space, c) }, :internal => c.name("fseg[internal]") { Innodb::FsegEntry.get_inode(@space, c) }, } end end |
#garbage_offset ⇒ Object
A helper function to return the offset to the first free record.
248 249 250 |
# File 'lib/innodb/page/index.rb', line 248 def garbage_offset page_header && page_header[:garbage_offset] end |
#header_space ⇒ Object
The amount of space consumed by the page header.
161 162 163 164 165 |
# File 'lib/innodb/page/index.rb', line 161 def header_space # The end of the supremum system record is the beginning of the space # available for user records. pos_user_records end |
#infimum ⇒ Object
Return the infimum record on a page.
441 442 443 |
# File 'lib/innodb/page/index.rb', line 441 def infimum @infimum ||= system_record(pos_infimum) end |
#level ⇒ Object
A helper function to return the page level from the "page" header, for easier access.
232 233 234 |
# File 'lib/innodb/page/index.rb', line 232 def level page_header && page_header[:level] end |
#make_record_description ⇒ Object
Return a set of field objects that describe the record.
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/innodb/page/index.rb', line 451 def make_record_description description = record_describer.cursor_sendable_description(self) position = 0 fields = {:type => description[:type], :key => [], :row => []} description[:key].each do |d| fields[:key] << Innodb::Field.new(position, *d) position += 1 end # Account for TRX_ID and ROLL_PTR. position += 2 description[:row].each do |d| fields[:row] << Innodb::Field.new(position, *d) position += 1 end fields end |
#page_header ⇒ Object
Return the "index" header.
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/innodb/page/index.rb', line 205 def page_header @page_header ||= cursor(pos_index_header).name("index") do |c| index = { :n_dir_slots => c.name("n_dir_slots") { c.get_uint16 }, :heap_top => c.name("heap_top") { c.get_uint16 }, :n_heap_format => c.name("n_heap_format") { c.get_uint16 }, :garbage_offset => c.name("garbage_offset") { c.get_uint16 }, :garbage_size => c.name("garbage_size") { c.get_uint16 }, :last_insert_offset => c.name("last_insert_offset") { c.get_uint16 }, :direction => c.name("direction") { PAGE_DIRECTION[c.get_uint16] }, :n_direction => c.name("n_direction") { c.get_uint16 }, :n_recs => c.name("n_recs") { c.get_uint16 }, :max_trx_id => c.name("max_trx_id") { c.get_uint64 }, :level => c.name("level") { c.get_uint16 }, :index_id => c.name("index_id") { c.get_uint64 }, } index[:n_heap] = index[:n_heap_format] & (2**15-1) index[:format] = (index[:n_heap_format] & 1<<15) == 0 ? :redundant : :compact index.delete :n_heap_format index end end |
#pos_directory ⇒ Object
The position of the page directory, which starts at the "fil" trailer and grows backwards from there.
156 157 158 |
# File 'lib/innodb/page/index.rb', line 156 def pos_directory pos_fil_trailer end |
#pos_fseg_header ⇒ Object
Return the byte offset of the start of the "fseg" header, which immediately follows the "index" header.
82 83 84 |
# File 'lib/innodb/page/index.rb', line 82 def pos_fseg_header pos_index_header + size_index_header end |
#pos_index_header ⇒ Object
Return the byte offset of the start of the "index" page header, which immediately follows the "fil" header.
71 72 73 |
# File 'lib/innodb/page/index.rb', line 71 def pos_index_header pos_fil_header + size_fil_header end |
#pos_infimum ⇒ Object
Return the byte offset of the start of the "origin" of the infimum record, which is always the first record in the singly-linked record chain on any page, and represents a record with a "lower value than any possible user record". The infimum record immediately follows the page header.
123 124 125 126 127 |
# File 'lib/innodb/page/index.rb', line 123 def pos_infimum pos_records + size_record_header + size_mum_record_header_additional end |
#pos_records ⇒ Object
Return the byte offset of the start of records within the page (the position immediately after the page header).
142 143 144 145 146 |
# File 'lib/innodb/page/index.rb', line 142 def pos_records size_fil_header + size_index_header + size_fseg_header end |
#pos_supremum ⇒ Object
Return the byte offset of the start of the "origin" of the supremum record, which is always the last record in the singly-linked record chain on any page, and represents a record with a "higher value than any possible user record". The supremum record immediately follows the infimum record.
133 134 135 136 137 138 |
# File 'lib/innodb/page/index.rb', line 133 def pos_supremum pos_infimum + size_record_header + size_mum_record_header_additional + size_mum_record end |
#pos_user_records ⇒ Object
Return the byte offset of the start of the user records in a page, which immediately follows the supremum record.
150 151 152 |
# File 'lib/innodb/page/index.rb', line 150 def pos_user_records pos_supremum + size_mum_record end |
#record(offset) ⇒ Object
Parse and return a record at a given offset.
481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 |
# File 'lib/innodb/page/index.rb', line 481 def record(offset) return nil unless offset return infimum if offset == pos_infimum return supremum if offset == pos_supremum cursor(offset).forward.name("record[#{offset}]") do |c| # There is a header preceding the row itself, so back up and read it. header = c.peek { record_header(c) } this_record = { :format => page_header[:format], :offset => offset, :header => header, :next => header[:next] == 0 ? nil : (header[:next]), } if record_format this_record[:type] = record_format[:type] # Read the key fields present in all types of pages. this_record[:key] = [] this_record[:key_ext] = [] c.name("key") do record_format[:key].each do |f| this_record[:key].push f.read(this_record, c) this_record[:key_ext].push f.read_extern(this_record, c) end end # If this is a leaf page of the clustered index, read InnoDB's internal # fields, a transaction ID and roll pointer. if level == 0 && record_format[:type] == :clustered this_record[:transaction_id] = c.name("transaction_id") { c.get_hex(6) } c.name("roll_pointer") do rseg_id_insert_flag = c.name("rseg_id_insert_flag") { c.get_uint8 } this_record[:roll_pointer] = { :is_insert => (rseg_id_insert_flag & 0x80) == 0x80, :rseg_id => rseg_id_insert_flag & 0x7f, :undo_log => c.name("undo_log") { { :page => c.name("page") { c.get_uint32 }, :offset => c.name("offset") { c.get_uint16 }, } } } end end # If this is a leaf page of the clustered index, or any page of a # secondary index, read the non-key fields. if (level == 0 && record_format[:type] == :clustered) || (record_format[:type] == :secondary) # Read the non-key fields. this_record[:row] = [] this_record[:row_ext] = [] c.name("row") do record_format[:row].each do |f| this_record[:row].push f.read(this_record, c) this_record[:row_ext].push f.read_extern(this_record, c) end end end # If this is a node (non-leaf) page, it will have a child page number # (or "node pointer") stored as the last field. if level > 0 # Read the node pointer in a node (non-leaf) page. this_record[:child_page_number] = c.name("child_page_number") { c.get_uint32 } end end this_record end end |
#record_bytes ⇒ Object
Return the actual bytes of the portion of the page which is used to store user records (eliminate the headers and trailer from the page).
200 201 202 |
# File 'lib/innodb/page/index.rb', line 200 def record_bytes data(pos_user_records, page_header[:heap_top] - pos_user_records) end |
#record_cursor(offset) ⇒ Object
Return a RecordCursor starting at offset.
587 588 589 |
# File 'lib/innodb/page/index.rb', line 587 def record_cursor(offset) RecordCursor.new(self, offset) end |
#record_format ⇒ Object
Return (and cache) the record format provided by an external class.
474 475 476 477 478 |
# File 'lib/innodb/page/index.rb', line 474 def record_format if record_describer @record_format ||= make_record_description() end end |
#record_header(cursor) ⇒ Object
Return the header from a record.
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 |
# File 'lib/innodb/page/index.rb', line 267 def record_header(cursor) origin = cursor.position header = {} cursor.backward.name("header") do |c| case page_header[:format] when :compact # The "next" pointer is a relative offset from the current record. header[:next] = c.name("next") { origin + c.get_sint16 } # Fields packed in a 16-bit integer (LSB first): # 3 bits for type # 13 bits for heap_number bits1 = c.name("bits1") { c.get_uint16 } header[:type] = RECORD_TYPES[bits1 & 0x07] header[:heap_number] = (bits1 & 0xf8) >> 3 when :redundant # The "next" pointer is an absolute offset within the page. header[:next] = c.name("next") { c.get_uint16 } # Fields packed in a 24-bit integer (LSB first): # 1 bit for offset_size (0 = 2 bytes, 1 = 1 byte) # 10 bits for n_fields # 13 bits for heap_number bits1 = c.name("bits1") { c.get_uint24 } header[:offset_size] = (bits1 & 1) == 0 ? 2 : 1 header[:n_fields] = (bits1 & (((1 << 10) - 1) << 1)) >> 1 header[:heap_number] = (bits1 & (((1 << 13) - 1) << 11)) >> 11 end # Fields packed in an 8-bit integer (LSB first): # 4 bits for n_owned # 4 bits for flags bits2 = c.name("bits2") { c.get_uint8 } header[:n_owned] = bits2 & 0x0f info = (bits2 & 0xf0) >> 4 header[:min_rec] = (info & RECORD_INFO_MIN_REC_FLAG) != 0 header[:deleted] = (info & RECORD_INFO_DELETED_FLAG) != 0 case page_header[:format] when :compact record_header_compact_additional(header, cursor) when :redundant record_header_redundant_additional(header, cursor) end end header end |
#record_header_compact_additional(header, cursor) ⇒ Object
Read additional header information from a compact format record header.
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/innodb/page/index.rb', line 317 def record_header_compact_additional(header, cursor) case header[:type] when :conventional, :node_pointer # The variable-length part of the record header contains a # bit vector indicating NULL fields and the length of each # non-NULL variable-length field. if record_format header[:field_nulls] = cursor.name("field_nulls") { record_header_compact_null_bitmap(cursor) } header[:field_lengths], header[:field_externs] = cursor.name("field_lengths_and_externs") { record_header_compact_variable_lengths_and_externs(cursor, header[:field_nulls]) } end end end |
#record_header_compact_null_bitmap(cursor) ⇒ Object
Return an array indicating which fields are null.
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/innodb/page/index.rb', line 337 def record_header_compact_null_bitmap(cursor) fields = (record_format[:key] + record_format[:row]) # The number of bits in the bitmap is the number of nullable fields. size = fields.count { |f| f.type.nullable? } # There is no bitmap if there are no nullable fields. return nil unless size > 0 # To simplify later checks, expand bitmap to one for each field. bitmap = Array.new(fields.last.position + 1, false) null_bit_array = cursor.get_bit_array(size).reverse! # For every nullable field, set whether the field is actually null. fields.each do |f| bitmap[f.position] = f.type.nullable? ? (null_bit_array.shift == 1) : false end return bitmap end |
#record_header_compact_variable_lengths_and_externs(cursor, null_bitmap) ⇒ Object
Return an array containing an array of the length of each variable-length field and an array indicating which fields are stored externally.
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'lib/innodb/page/index.rb', line 361 def record_header_compact_variable_lengths_and_externs(cursor, null_bitmap) fields = (record_format[:key] + record_format[:row]) len_array = Array.new(fields.last.position + 1, 0) ext_array = Array.new(fields.last.position + 1, false) # For each non-NULL variable-length field, the record header contains # the length in one or two bytes. fields.each do |f| next if !f.type.variable? or (null_bitmap && null_bitmap[f.position]) len = cursor.get_uint8 ext = false # Two bytes are used only if the length exceeds 127 bytes and the # maximum length exceeds 255 bytes (or the field is a BLOB type). if len > 127 && (f.type.blob? || f.type.length > 255) ext = (0x40 & len) != 0 len = ((len & 0x3f) << 8) + cursor.get_uint8 end len_array[f.position] = len ext_array[f.position] = ext end return len_array, ext_array end |
#record_header_redundant_additional(header, cursor) ⇒ Object
Read additional header information from a redundant format record header.
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
# File 'lib/innodb/page/index.rb', line 390 def record_header_redundant_additional(header, cursor) header[:field_lengths] = [] header[:field_nulls] = [] header[:field_externs] = [] field_offsets = record_header_redundant_field_end_offsets(header, cursor) this_field_offset = 0 field_offsets.each do |n| case header[:offset_size] when 1 next_field_offset = (n & RECORD_REDUNDANT_OFF1_OFFSET_MASK) header[:field_lengths] << (next_field_offset - this_field_offset) header[:field_nulls] << ((n & RECORD_REDUNDANT_OFF1_NULL_MASK) != 0) header[:field_externs] << false when 2 next_field_offset = (n & RECORD_REDUNDANT_OFF2_OFFSET_MASK) header[:field_lengths] << (next_field_offset - this_field_offset) header[:field_nulls] << ((n & RECORD_REDUNDANT_OFF2_NULL_MASK) != 0) header[:field_externs] << ((n & RECORD_REDUNDANT_OFF2_EXTERN_MASK) != 0) end this_field_offset = next_field_offset end end |
#record_header_redundant_field_end_offsets(header, cursor) ⇒ Object
Read field end offsets from the provided cursor for each field as counted by n_fields.
417 418 419 420 421 422 423 424 |
# File 'lib/innodb/page/index.rb', line 417 def record_header_redundant_field_end_offsets(header, cursor) (0...header[:n_fields]).to_a.inject([]) do |offsets, n| cursor.name("field_end_offset[#{n}]") { offsets << cursor.get_uint_by_size(header[:offset_size]) } offsets end end |
#record_space ⇒ Object
Return the amount of space occupied by records in the page.
194 195 196 |
# File 'lib/innodb/page/index.rb', line 194 def record_space used_space - header_space - directory_space - trailer_space end |
#records ⇒ Object
A helper function to return the number of records.
237 238 239 |
# File 'lib/innodb/page/index.rb', line 237 def records page_header && page_header[:n_recs] end |
#root? ⇒ Boolean
A helper function to identify root index pages; they must be the only pages at their level.
243 244 245 |
# File 'lib/innodb/page/index.rb', line 243 def root? self.prev.nil? && self.next.nil? end |
#size_fseg_header ⇒ Object
The size of the "fseg" header.
87 88 89 |
# File 'lib/innodb/page/index.rb', line 87 def size_fseg_header 2 * Innodb::FsegEntry::SIZE end |
#size_index_header ⇒ Object
The size of the "index" header.
76 77 78 |
# File 'lib/innodb/page/index.rb', line 76 def size_index_header 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 2 + 8 + 2 + 8 end |
#size_mum_record ⇒ Object
The size of the data from the supremum or infimum records.
115 116 117 |
# File 'lib/innodb/page/index.rb', line 115 def size_mum_record 8 end |
#size_mum_record_header_additional ⇒ Object
The size of the additional data structures in the header of the system records, which is just 1 byte in redundant format to store the offset of the end of the field. This is needed specifically here since we need to be able to calculate the fixed positions of these system records.
105 106 107 108 109 110 111 112 |
# File 'lib/innodb/page/index.rb', line 105 def size_mum_record_header_additional case page_header[:format] when :compact 0 # No additional data is stored in compact format. when :redundant 1 # A 1-byte offset for 1 field is stored in redundant format. end end |
#size_record_header ⇒ Object
Return the size of the header for each record.
92 93 94 95 96 97 98 99 |
# File 'lib/innodb/page/index.rb', line 92 def size_record_header case page_header[:format] when :compact RECORD_NEXT_SIZE + RECORD_COMPACT_BITS_SIZE when :redundant RECORD_NEXT_SIZE + RECORD_REDUNDANT_BITS_SIZE end end |
#supremum ⇒ Object
Return the supremum record on a page.
446 447 448 |
# File 'lib/innodb/page/index.rb', line 446 def supremum @supremum ||= system_record(pos_supremum) end |
#system_record(offset) ⇒ Object
Parse and return simple fixed-format system records, such as InnoDB's internal infimum and supremum records.
428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/innodb/page/index.rb', line 428 def system_record(offset) cursor(offset).name("record[#{offset}]") do |c| header = c.peek { record_header(c) } { :offset => offset, :header => header, :next => header[:next], :data => c.name("data") { c.get_bytes(size_mum_record) }, } end end |
#trailer_space ⇒ Object
The amount of space consumed by the trailers in the page.
178 179 180 |
# File 'lib/innodb/page/index.rb', line 178 def trailer_space size_fil_trailer end |
#used_space ⇒ Object
Return the amount of used space in the page.
189 190 191 |
# File 'lib/innodb/page/index.rb', line 189 def used_space size - free_space end |