diff --git a/mysql-test/main/win.result b/mysql-test/main/win.result index 08668965cf6..317f39526c8 100644 --- a/mysql-test/main/win.result +++ b/mysql-test/main/win.result @@ -3866,6 +3866,32 @@ NULL DROP VIEW v1; DROP TABLE t1,t2; # +# MDEV-25032 Window functions without column references get removed from ORDER BY +# +create table t1 (id int, score double); +insert into t1 values +(1, 5), +(1, 6), +(1, 6), +(1, 6), +(1, 7), +(1, 8.1), +(1, 9), +(1, 10); +select id, row_number() over () rn +from t1 +order by rn desc; +id rn +1 8 +1 7 +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +drop table t1; +# # End of 10.2 tests # # diff --git a/mysql-test/main/win.test b/mysql-test/main/win.test index bc2f6144985..a83698ce0d4 100644 --- a/mysql-test/main/win.test +++ b/mysql-test/main/win.test @@ -2522,6 +2522,26 @@ SELECT NTH_VALUE(i1, i1) OVER (PARTITION BY i1) FROM v1; DROP VIEW v1; DROP TABLE t1,t2; +--echo # +--echo # MDEV-25032 Window functions without column references get removed from ORDER BY +--echo # + +create table t1 (id int, score double); +insert into t1 values +(1, 5), +(1, 6), +(1, 6), +(1, 6), +(1, 7), +(1, 8.1), +(1, 9), +(1, 10); +select id, row_number() over () rn +from t1 +order by rn desc; + +drop table t1; + --echo # --echo # End of 10.2 tests --echo # diff --git a/mysql-test/suite/encryption/r/tempfiles_encrypted.result b/mysql-test/suite/encryption/r/tempfiles_encrypted.result index 09512363be4..1047dde635b 100644 --- a/mysql-test/suite/encryption/r/tempfiles_encrypted.result +++ b/mysql-test/suite/encryption/r/tempfiles_encrypted.result @@ -3872,6 +3872,32 @@ NULL DROP VIEW v1; DROP TABLE t1,t2; # +# MDEV-25032 Window functions without column references get removed from ORDER BY +# +create table t1 (id int, score double); +insert into t1 values +(1, 5), +(1, 6), +(1, 6), +(1, 6), +(1, 7), +(1, 8.1), +(1, 9), +(1, 10); +select id, row_number() over () rn +from t1 +order by rn desc; +id rn +1 8 +1 7 +1 6 +1 5 +1 4 +1 3 +1 2 +1 1 +drop table t1; +# # End of 10.2 tests # # diff --git a/mysql-test/suite/innodb/r/innodb.result b/mysql-test/suite/innodb/r/innodb.result index 25f3e0bc68e..9e7cd74baee 100644 --- a/mysql-test/suite/innodb/r/innodb.result +++ b/mysql-test/suite/innodb/r/innodb.result @@ -3318,3 +3318,20 @@ c1 c2 9 3 DROP TABLE t1; DROP TABLE t2; +# +# MDEV-24748 Extern field check missing +# in btr_index_rec_validate() +# +CREATE TABLE t1 (pk INT, c1 char(255), +c2 char(255), c3 char(255), c4 char(255), +c5 char(255), c6 char(255), c7 char(255), +c8 char(255), primary key (pk) +) CHARACTER SET utf32 ENGINE=InnoDB; +INSERT INTO t1 VALUES +(1, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), +(2, 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'); +CHECK TABLE t1; +Table Op Msg_type Msg_text +test.t1 check status OK +ALTER TABLE t1 FORCE; +DROP TABLE t1; diff --git a/mysql-test/suite/innodb/t/innodb.test b/mysql-test/suite/innodb/t/innodb.test index 37708a4536d..a7f8159d61b 100644 --- a/mysql-test/suite/innodb/t/innodb.test +++ b/mysql-test/suite/innodb/t/innodb.test @@ -2593,3 +2593,21 @@ SELECT * FROM t2; DROP TABLE t1; DROP TABLE t2; + +--echo # +--echo # MDEV-24748 Extern field check missing +--echo # in btr_index_rec_validate() +--echo # +CREATE TABLE t1 (pk INT, c1 char(255), +c2 char(255), c3 char(255), c4 char(255), +c5 char(255), c6 char(255), c7 char(255), +c8 char(255), primary key (pk) +) CHARACTER SET utf32 ENGINE=InnoDB; + +INSERT INTO t1 VALUES + (1, 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'), + (2, 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'); +CHECK TABLE t1; +ALTER TABLE t1 FORCE; +# Cleanup +DROP TABLE t1; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index b83da48233d..5f8bd24032f 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -13416,6 +13416,7 @@ remove_const(JOIN *join,ORDER *first_order, COND *cond, { table_map order_tables=order->item[0]->used_tables(); if (order->item[0]->with_sum_func || + order->item[0]->with_window_func || /* If the outer table of an outer join is const (either by itself or after applying WHERE condition), grouping on a field from such a diff --git a/storage/innobase/btr/btr0btr.cc b/storage/innobase/btr/btr0btr.cc index ebe6bf57d15..2c5e7f96655 100644 --- a/storage/innobase/btr/btr0btr.cc +++ b/storage/innobase/btr/btr0btr.cc @@ -4547,6 +4547,18 @@ btr_index_rec_validate( rec_get_nth_field_offs(offsets, i, &len); + if (rec_offs_nth_extern(offsets, i)) { + + const byte* data = rec_get_nth_field( + rec, offsets, i, &len); + len -= BTR_EXTERN_FIELD_REF_SIZE; + ulint extern_len = mach_read_from_4( + data + len + BTR_EXTERN_LEN + 4); + if (fixed_size == extern_len) { + continue; + } + } + /* Note that if fixed_size != 0, it equals the length of a fixed-size column in the clustered index. We should adjust it here. diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index d3d8e390639..e1c1e1d7d21 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1000,15 +1000,14 @@ fil_space_extend_must_retry( } -/*******************************************************************//** -Reserves the fil_system.mutex and tries to make sure we can open at least one +/** Reserves the fil_system.mutex and tries to make sure we can open at least one file while holding it. This should be called before calling -fil_node_prepare_for_io(), because that function may need to open a file. */ +fil_node_prepare_for_io(), because that function may need to open a file. +@param[in] space_id tablespace id +@return whether the tablespace is usable for io */ static -void -fil_mutex_enter_and_prepare_for_io( -/*===============================*/ - ulint space_id) /*!< in: space id */ +bool +fil_mutex_enter_and_prepare_for_io(ulint space_id) { for (ulint count = 0;;) { mutex_enter(&fil_system.mutex); @@ -1021,7 +1020,7 @@ fil_mutex_enter_and_prepare_for_io( fil_space_t* space = fil_space_get_by_id(space_id); if (space == NULL) { - break; + return false; } fil_node_t* node = UT_LIST_GET_LAST(space->chain); @@ -1036,6 +1035,10 @@ fil_mutex_enter_and_prepare_for_io( the insert buffer. The insert buffer is in tablespace 0, and we cannot end up waiting in this function. */ + } else if (space->is_stopping() && !space->is_being_truncated) { + /* If the tablespace is being deleted then InnoDB + shouldn't prepare the tablespace for i/o */ + return false; } else if (!node || node->is_open()) { /* If the file is already open, no need to do anything; if the space does not exist, we handle the @@ -1107,6 +1110,8 @@ fil_mutex_enter_and_prepare_for_io( break; } + + return true; } /** Try to extend a tablespace if it is smaller than the specified size. @@ -1123,7 +1128,10 @@ fil_space_extend( bool success; do { - fil_mutex_enter_and_prepare_for_io(space->id); + if (!fil_mutex_enter_and_prepare_for_io(space->id)) { + success = false; + break; + } } while (fil_space_extend_must_retry( space, UT_LIST_GET_LAST(space->chain), size, &success)); @@ -1478,7 +1486,9 @@ fil_space_t* fil_system_t::read_page0(ulint id) /* It is possible that the tablespace is dropped while we are not holding the mutex. */ - fil_mutex_enter_and_prepare_for_io(id); + if (!fil_mutex_enter_and_prepare_for_io(id)) { + return NULL; + } fil_space_t* space = fil_space_get_by_id(id);