diff options
author | Jacob Mathew <jacob.mathew@mariadb.com> | 2018-02-19 19:19:03 -0800 |
---|---|---|
committer | Jacob Mathew <jacob.mathew@mariadb.com> | 2018-02-19 21:36:19 -0800 |
commit | 884b83e28fed3d6de2593d5b4121dc23fce7f921 (patch) | |
tree | f56e51de430a099966b3a99cefd9a78ea6057ce8 /sql/filesort.h | |
parent | d23fcc427cb4010b33defc69547089afeb9af811 (diff) | |
download | mariadb-git-bb-10.3-MDEV-14500.tar.gz |
MDEV-14500: Support engines without rnd_pos() andbb-10.3-MDEV-14500
engines with inefficient rnd_pos()
Some engines have not implemented rnd_pos(). There are other engines whose
implementation of rnd_pos() is inherently inefficient. Spider is such an
engine, whose implementation of rnd_pos() needs to access a table on a remote
data node to retrieve a single table row.
To address these limitations, a new temporary table has been added to filesort.
When filesort sequentially reads the table being sorted, each row is written to
the filesort temp table in addition to being copied to the sort buffer.
Subsequent calls to rnd_pos() will then access the table row in the filesort
temp table instead of in the table being sorted.
The following logic changes incorporate the new filesort temp table into the
server:
- A new handler method to determine whether a call to the engine's
rnd_pos() is expensive. The default return value is FALSE. Engines without
rnd_pos() or with an inefficient rnd_pos() should return TRUE.
- Create the filesort temp table only if:
- There are no add-on columns for filesort; and
- The engine's implementation of rnd_pos() is expensive.
- Write to the temp table each row that is read from the table being sorted.
- Do subsequent row retrievals that use rnd_pos() on the temp table instead of
on the table being sorted. Upon retrieving a row from the temp table, copy
its column values to the record of the table being sorted.
- Upon completion of retrieval of the sorted result rows, delete the filesort
temp table and free the memory allocated for using it.
The logic changes are in the following areas:
- Table handler.
- Partition engine.
- Spider engine.
- Filesort.
- Read record manager.
Note that these changes only address the use of rnd_pos() by filesort. They do
not address the use of rnd_pos() in other areas such as:
- Quick select.
- Insert.
- Update.
- Window functions.
- Multi Range Read.
Author:
Jacob Mathew.
Reviewer:
Sergei Golubchik.
Diffstat (limited to 'sql/filesort.h')
-rw-r--r-- | sql/filesort.h | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/sql/filesort.h b/sql/filesort.h index bd1d81f91ef..60b21ffab47 100644 --- a/sql/filesort.h +++ b/sql/filesort.h @@ -27,6 +27,7 @@ class Filesort_tracker; struct SORT_FIELD; typedef struct st_order ORDER; class JOIN; +class Copy_field; /** @@ -87,7 +88,8 @@ class SORT_INFO public: SORT_INFO() - :addon_field(0), record_pointers(0) + :addon_field(0), record_pointers(0), + fs_tmp_table(NULL), tmp_field(NULL), tmp_fields(0) { buffpek.str= 0; my_b_clear(&io_cache); @@ -101,6 +103,9 @@ public: my_free(record_pointers); my_free(buffpek.str); my_free(addon_field); + fs_tmp_table= NULL; // Freed in end_read_record() + tmp_field= NULL; // Freed in end_read_record() + tmp_fields= 0; } void reset() @@ -119,6 +124,11 @@ public: /* To unpack back */ void (*unpack)(struct st_sort_addon_field *, uchar *, uchar *); uchar *record_pointers; /* If sorted in memory */ + TABLE *fs_tmp_table; /* Optional temp table used by filesort to */ + /* eliminate rnd_pos() calls to the table + /* being sorted */ + Copy_field *tmp_field; /* Filesort temp table field array */ + uint tmp_fields; /* Number of filesort temp table fields */ /* How many rows in final result. Also how many rows in record_pointers, if used |