mirror of
https://github.com/MariaDB/server.git
synced 2026-10-23 18:49:29 +03:00
Seven code fixes, a new test, and test re-recordings for issues found by CI on PR #5222. **NULL dereference in `create_tmp_field()`**: `SYS_REFCURSOR` plugin returns NULL from `make_new_field()` (cursor values cannot be materialized). The feature added `result->flags |= FIELD_PART_OF_TMP_UNIQUE` without a NULL check. Added `if (result)` guard. **xmltype identity loss and recursive CTE reclength mismatch in `Item_type_holder::create_tmp_field_ex()`**: the blob_key dispatch now requires both: (1) `type_handler_for_tmp_table()` returns `blob_key_type_handler()`, AND (2) `dynamic_cast<Type_handler_blob_common*>` confirms the original type is a native blob. Condition 1 excludes xmltype (its override returns itself). Condition 2 excludes VARCHAR types promoted via `varstring_type_handler()` -> `too_big_for_varchar()` -> `blob_type_handler()`. Without condition 2, wide VARCHAR in recursive CTEs (e.g. `cast('...' as varchar(1000))`) was promoted to `Field_blob_key` in the main UNION DISTINCT table (`part_of_unique_key=true`) but stayed as `Field_varchar` in the incremental table (`part_of_unique_key=false`), causing a `reclength` mismatch assertion in `select_union_recursive::send_data()` (`main.json_equals` crash). **Spurious `reclength > HA_MAX_REC_LENGTH` in `pick_engine()`**: the original `choose_engine()` (both 10.11 and upstream/main) never had a reclength check. MDEV-38975 introduced it when replacing the `blob_fields` condition. HEAP has no internal reclength limit -- `hp_create.c` stores `uint reclength` and allocates blocks of that size; `max_supported_record_length()` is only checked in `unireg.cc` during user-facing CREATE TABLE. I_S tables like SLAVE_STATUS routinely have reclength ~880KB (13 bare `Varchar()` columns). The check forced them to Aria where `fill_slave_status()` returned 0 rows. Removed the check and the unused `reclength` parameter from `pick_engine()`. **Multi-update `tmp_memory_table_size` override**: the 10.11 feature overrode `big_tables=FALSE` for multi-update dedup tables. The forward-port translated this as `tmp_memory_table_size=SIZE_T_MAX` when the variable was 0. But `big_tables=FALSE` was a soft "don't force disk" hint, while `tmp_memory_table_size=SIZE_T_MAX` overrides the user's explicit `tmp_memory_table_size=0` directive. Since main removed `big_tables` entirely (MDEV-19713), the override is not needed. Removed. **Zero-length key rejection in `check_tmp_key()`**: reject `key_len == 0` to prevent useless zero-length keys from being created by `add_tmp_key()`. Reachable when all key parts are CHAR(0) NOT NULL: `key_length()` returns 0, the field is not nullable (no HA_KEY_NULL_LENGTH) and not VARCHAR/BLOB/GEOMETRY (no HA_KEY_BLOB_LENGTH), so `fld_store_len` is 0 for every part. Without this guard, `check_tmp_key()` would accept the key (0 <= max_key_length), and the optimizer would create a ref key that cannot distinguish any rows. Added `heap.char0_key` test exercising this via a materialized derived table with CHAR(0) NOT NULL join columns. **Non-deterministic `column_compression` test**: HEAP blob support allows compressed VARCHAR/TEXT temp tables to stay in HEAP instead of falling to Aria, changing row iteration order. Added `--sorted_result` to the two MDEV-24726 subqueries that lack `ORDER BY`. Test changes: - `spatial_utility_function_collect`: added ORDER BY to window function that lacked it (results were engine-row-order-dependent) - `tmp_space_usage`: removed multi-update override; forced disk for MDEV-34016/34060 Aria-specific test sections (blob I_S tables now stay in MEMORY) - `blob_update_overflow`: replaced `SHOW STATUS LIKE 'Created_tmp_%'` with targeted I_S query (Created_tmp_files varies on sanitizer builds) - 'funcs_1.is_tables_is' ; re-recorded test as INFORMATION_SCHEMA.SLAVE_STATUS is now back as MEMORY table - `column_compression`: added `--sorted_result` for MDEV-24726 queries - `char0_key` (new): CHAR(0) NOT NULL derived table ref key rejection - Re-recorded 8 tests for expected "temp table stays in MEMORY" changes
83 lines
2.8 KiB
C++
83 lines
2.8 KiB
C++
#ifndef CREATE_TMP_TABLE_INCLUDED
|
|
#define CREATE_TMP_TABLE_INCLUDED
|
|
|
|
/* Copyright (c) 2021, MariaDB Corporation.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; version 2 of the License.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
|
|
|
|
|
|
/*
|
|
Class for creating internal tempory tables in sql_select.cc
|
|
*/
|
|
|
|
class Create_tmp_table: public Data_type_statistics
|
|
{
|
|
protected:
|
|
// The following members are initialized only in start()
|
|
Field **m_from_field, **m_default_field;
|
|
KEY_PART_INFO *m_key_part_info;
|
|
uchar *m_group_buff, *m_bitmaps;
|
|
// The following members are initialized in ctor
|
|
uint m_alloced_field_count;
|
|
bool m_using_unique_constraint;
|
|
bool m_heap_expected;
|
|
uint m_temp_pool_slot;
|
|
ORDER *m_group;
|
|
bool m_distinct;
|
|
bool m_save_sum_fields;
|
|
bool m_with_cycle;
|
|
ulonglong m_select_options;
|
|
ha_rows m_rows_limit;
|
|
uint m_group_null_items;
|
|
|
|
// counter for distinct/other fields
|
|
uint m_field_count[2];
|
|
// counter for distinct/other fields which can be NULL
|
|
uint m_null_count[2];
|
|
// counter for distinct/other blob fields
|
|
uint m_blobs_count[2];
|
|
// counter for "tails" of bit fields which do not fit in a byte
|
|
uint m_uneven_bit[2];
|
|
|
|
public:
|
|
enum counter {distinct, other};
|
|
/*
|
|
shows which field we are processing: distinct/other (set in processing
|
|
cycles)
|
|
*/
|
|
counter current_counter;
|
|
Create_tmp_table(ORDER *group, bool distinct, bool save_sum_fields,
|
|
ulonglong select_options, ha_rows rows_limit);
|
|
virtual ~Create_tmp_table() {}
|
|
handlerton *pick_engine(THD *thd);
|
|
virtual bool choose_engine(THD *thd, TABLE *table, TMP_TABLE_PARAM *param);
|
|
void add_field(TABLE *table, Field *field, uint fieldnr,
|
|
bool force_not_null_cols);
|
|
TABLE *start(THD *thd,
|
|
TMP_TABLE_PARAM *param,
|
|
const LEX_CSTRING *table_alias);
|
|
bool add_fields(THD *thd, TABLE *table,
|
|
TMP_TABLE_PARAM *param, List<Item> &fields);
|
|
|
|
bool add_schema_fields(THD *thd, TABLE *table,
|
|
TMP_TABLE_PARAM *param,
|
|
const ST_SCHEMA_TABLE &schema_table);
|
|
|
|
bool finalize(THD *thd, TABLE *table, TMP_TABLE_PARAM *param,
|
|
bool do_not_open, bool keep_row_order);
|
|
void cleanup_on_failure(THD *thd, TABLE *table);
|
|
};
|
|
|
|
#endif /* CREATE_TMP_TABLE_INCLUDED */
|