MCPcopy Create free account
hub / github.com/MariaDB/server / setup_buffer_sharing

Method setup_buffer_sharing

sql/multi_range_read.cc:1527–1576  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1525*/
1526
1527bool DsMrr_impl::setup_buffer_sharing(uint key_size_in_keybuf,
1528 key_part_map key_tuple_map)
1529{
1530 long key_buff_elem_size= key_size_in_keybuf +
1531 (int)is_mrr_assoc * sizeof(range_id_t);
1532
1533 KEY *key_info= &primary_file->get_table()->key_info[keyno];
1534 /*
1535 Ok if we got here we need to allocate one part of the buffer
1536 for keys and another part for rowids.
1537 */
1538 ulonglong rowid_buf_elem_size= primary_file->ref_length +
1539 (int)is_mrr_assoc * sizeof(range_id_t);
1540
1541 /*
1542 Use rec_per_key statistics as a basis to find out how many rowids
1543 we'll get for each key value.
1544 TODO: what should be the default value to use when there is no
1545 statistics?
1546 */
1547 uint parts= my_count_bits(key_tuple_map);
1548 ha_rows rpc;
1549 ulonglong rowids_size= rowid_buf_elem_size;
1550 if ((rpc= (ha_rows) key_info->actual_rec_per_key(parts - 1)))
1551 rowids_size= rowid_buf_elem_size * rpc;
1552
1553 double fraction_for_rowids=
1554 (ulonglong2double(rowids_size) /
1555 (ulonglong2double(rowids_size) + key_buff_elem_size));
1556
1557 ptrdiff_t bytes_for_rowids=
1558 (ptrdiff_t)floor(0.5 + fraction_for_rowids * (full_buf_end - full_buf));
1559
1560 ptrdiff_t bytes_for_keys= (full_buf_end - full_buf) - bytes_for_rowids;
1561
1562 if (bytes_for_keys < key_buff_elem_size + 1 ||
1563 bytes_for_rowids < (ptrdiff_t)rowid_buf_elem_size + 1)
1564 return TRUE; /* Failed to provide minimum space for one of the buffers */
1565
1566 rowid_buffer_end= full_buf + bytes_for_rowids;
1567 rowid_buffer.set_buffer_space(full_buf, rowid_buffer_end);
1568 key_buffer= &backward_key_buf;
1569 key_buffer->set_buffer_space(rowid_buffer_end, full_buf_end);
1570
1571 /* The above code guarantees that the buffers are big enough */
1572 DBUG_ASSERT(key_buffer->have_space_for(key_buff_elem_size) &&
1573 rowid_buffer.have_space_for((size_t)rowid_buf_elem_size));
1574
1575 return FALSE;
1576}
1577
1578
1579void DsMrr_impl::do_nothing(void *dsmrr_arg)

Callers

nothing calls this directly

Calls 5

my_count_bitsFunction · 0.85
actual_rec_per_keyMethod · 0.80
set_buffer_spaceMethod · 0.80
get_tableMethod · 0.45
have_space_forMethod · 0.45

Tested by

no test coverage detected