Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions mysql-test/suite/innodb/r/xtradb_compressed_columns.result
Original file line number Diff line number Diff line change
Expand Up @@ -324,3 +324,19 @@ UPDATE t1 SET ip_col=2680 WHERE ip_col = 23486;
UPDATE t1 SET ip_col=23486 WHERE ip_col = 2680;
include/assert.inc ['value inside lt3 compressed column should be valid']
DROP TABLE t1;

#
# Bug PS-10072: ALTER VARCHAR(253->254) on compressed column must not use inplace
#
CREATE TABLE t11(
c1 VARCHAR(253) COLUMN_FORMAT COMPRESSED
) CHARACTER SET ascii ENGINE=InnoDB;
INSERT INTO t11 VALUES (REPEAT('a', 253));
ALTER TABLE t11 MODIFY c1 VARCHAR(254) COLUMN_FORMAT COMPRESSED, ALGORITHM=INPLACE;
ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.
ALTER TABLE t11 MODIFY c1 VARCHAR(254) COLUMN_FORMAT COMPRESSED;
SELECT LENGTH(c1) FROM t11;
LENGTH(c1)
253
DROP TABLE t11;

14 changes: 14 additions & 0 deletions mysql-test/suite/innodb/t/xtradb_compressed_columns.test
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,17 @@ UPDATE t1 SET ip_col=23486 WHERE ip_col = 2680;
--source include/assert.inc

DROP TABLE t1;

--echo #
--echo # Bug PS-10072: ALTER VARCHAR(253->254) on compressed column must not use inplace
--echo #
CREATE TABLE t11(
c1 VARCHAR(253) COLUMN_FORMAT COMPRESSED
) CHARACTER SET ascii ENGINE=InnoDB;
INSERT INTO t11 VALUES (REPEAT('a', 253));
--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
ALTER TABLE t11 MODIFY c1 VARCHAR(254) COLUMN_FORMAT COMPRESSED, ALGORITHM=INPLACE;
ALTER TABLE t11 MODIFY c1 VARCHAR(254) COLUMN_FORMAT COMPRESSED;
SELECT LENGTH(c1) FROM t11;
DROP TABLE t11;

22 changes: 18 additions & 4 deletions sql/field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,26 @@ bool sql_type_prevents_inplace(const Field &from, const Create_field &to) {
*/
bool length_prevents_inplace(const Field &from, const Create_field &to) {
DBUG_TRACE;
constexpr size_t kCompressedColumnHeaderLength = 2;
const size_t to_row_pack_length =
to.max_display_width_in_bytes() +
(to.column_format() == COLUMN_FORMAT_TYPE_COMPRESSED
? kCompressedColumnHeaderLength
: 0);
const size_t from_row_pack_length =
from.row_pack_length() +
(from.column_format() == COLUMN_FORMAT_TYPE_COMPRESSED
? kCompressedColumnHeaderLength
: 0);

DBUG_PRINT(
"inplace",
("from:%p, to.field:%p, to.field->row_pack_length():%u, "
"to.max_display_width_in_bytes():%zu",
"to.max_display_width_in_bytes():%zu, from_row_pack_length:%zu, "
"to_row_pack_length:%zu",
&from, to.field, to.field ? to.field->row_pack_length() : (uint)-1,
to.max_display_width_in_bytes()));
to.max_display_width_in_bytes(), from_row_pack_length,
to_row_pack_length));

if (to.pack_length() < from.pack_length()) {
DBUG_PRINT(
Expand All @@ -170,11 +184,11 @@ bool length_prevents_inplace(const Field &from, const Create_field &to) {
return true;
}

if (to.max_display_width_in_bytes() >= 256 && from.row_pack_length() < 256) {
if (to_row_pack_length >= 256 && from_row_pack_length < 256) {
DBUG_PRINT("inplace",
("row_pack_length increases past the 256 threshold, from %u to "
"%zu, -> true for '%s'",
from.row_pack_length(), to.max_display_width_in_bytes(),
from.row_pack_length(), to_row_pack_length,
current_thd->query().str));
DBUG_PRINT("inplace",
("from:%p, to.field:%p, to.field->row_pack_length():%u", &from,
Expand Down