diff options
author | Mattias Jonsson <mattias.jonsson@oracle.com> | 2012-08-15 14:31:26 +0200 |
---|---|---|
committer | Mattias Jonsson <mattias.jonsson@oracle.com> | 2012-08-15 14:31:26 +0200 |
commit | bcee9f1896ab6015e77ea88fde5317f50edaead7 (patch) | |
tree | e7ca7e7a169f2abfe58034ccf619d538574434ca /sql/ha_partition.h | |
parent | 03bfc41bb83210ae4bdf16e6650f6168a2111ac0 (diff) | |
download | mariadb-git-bcee9f1896ab6015e77ea88fde5317f50edaead7.tar.gz |
Bug#13025132 - PARTITIONS USE TOO MUCH MEMORY
The buffer for the current read row from each partition
(m_ordered_rec_buffer) used for sorted reads was
allocated on open and freed when the ha_partition handler
was closed or destroyed.
For tables with many partitions and big records this could
take up too much valuable memory.
Solution is to only allocate the memory when it is needed
and free it when nolonger needed. I.e. allocate it in
index_init and free it in index_end (and to handle failures
also free it on reset, close etc.)
Also only allocating needed memory, according to
partitioning pruning.
Manually tested that it does not use as much memory and
releases it after queries.
Diffstat (limited to 'sql/ha_partition.h')
-rw-r--r-- | sql/ha_partition.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 7e6b062846a..a7e072a3b77 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -517,6 +517,8 @@ public: virtual int read_range_next(); private: + bool init_record_priority_queue(); + void destroy_record_priority_queue(); int common_index_read(uchar * buf, bool have_start_key); int common_first_last(uchar * buf); int partition_scan_set_up(uchar * buf, bool idx_read_flag); @@ -524,8 +526,15 @@ private: int handle_unordered_scan_next_partition(uchar * buf); uchar *queue_buf(uint part_id) { - return (m_ordered_rec_buffer + - (part_id * (m_rec_length + PARTITION_BYTES_IN_POS))); + uint16 *part_id_map= (uint16*) m_ordered_rec_buffer; + /* Offset to the partition's record buffer in number of partitions. */ + uint offset= part_id_map[part_id]; + /* + Return the pointer to the partition's record buffer. + First skip the partition id map, and then add the offset. + */ + return (m_ordered_rec_buffer + m_tot_parts * PARTITION_BYTES_IN_POS + + (offset * (m_rec_length + PARTITION_BYTES_IN_POS))); } uchar *rec_buf(uint part_id) { |