Bug #77656 Assert when running ALTER TABLE on a table with index on virtual column
Submitted: 8 Jul 2015 13:20 Modified: 20 Jul 2015 14:54
Reporter: Olav Sandstå Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Optimizer Severity:S3 (Non-critical)
Version: OS:Any
Assigned to: CPU Architecture:Any

[8 Jul 2015 13:20] Olav Sandstå
Description:

The following assert in my_eval_gcolumn_expr_helper() in handler.cc:

    res= field->gcol_info->expr_item->save_in_field(field, 0);
    DBUG_ASSERT(!thd->is_error() || res);

can sometimes hit when having an index on a virtual column and in the same table exists another virtual column that has a field number that is 64 higher.

The call stack:

#8  0x0000000000e75d60 in my_eval_gcolumn_expr_helper (thd=0x7fb5b40123d0, table=0x7fb5b40040c0, fields=4, record=0x7fb5b42b1530 "", in_purge=false) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/handler.cc:7942
#9  0x0000000000e762ed in handler::my_eval_gcolumn_expr (thd=0x7fb5b40123d0, db_name=0x7fb6162e0438 "test", table_name=0x7fb6162e0578 "#sql-284b_3", fields=4, record=0x7fb5b42b1530 "") at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/handler.cc:8108
#10 0x00000000018ce9ca in innobase_get_computed_value (row=0x7fb5b42fe0f8, col=0x7fb5b43464e0, index=0x7fb5b4e1b780, my_rec=0x0, local_heap=0x7fb6162dfa50, heap=0x0, in_purge=false) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/storage/innobase/handler/ha_innodb.cc:19680
#11 0x00000000019ea69d in row_merge_buf_add (buf=0x7fb5b4e18990, fts_index=0x0, old_table=0x7fb5b4e1cfa0, new_table=0x7fb5b4e129b0, psort_info=0x0, row=0x7fb5b42fe0f8, ext=0x0, doc_id=0x7fb6162dfa48, conv_heap=0x0, exceed_page=0x7fb6162dfa1f, v_heap=0x7fb6162dfa50) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/storage/innobase/row/row0merge.cc:584
#12 0x00000000019eed5c in row_merge_read_clustered_index (trx=0x7fb6290ca8b0, table=0x7fb5b40040c0, old_table=0x7fb5b4e1cfa0, new_table=0x7fb5b4e129b0, online=true, index=0x7fb5b4345f68, fts_sort_idx=0x0, psort_info=0x0, files=0x7fb5b434bfa8, key_numbers=0x7fb5b4345f78, n_index=2, add_cols=0x7fb5b4e16878, col_map=0x7fb5b4e18a70, add_autoinc=18446744073709551615, sequence=..., block=0x7fb6103ba000 <Address 0x7fb6103ba000 out of bounds>, skip_pk_sort=true, tmpfd=0x7fb6162dffcc, stage=0x7fb5b434bf38) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/storage/innobase/row/row0merge.cc:2140
#13 0x00000000019f4396 in row_merge_build_indexes (trx=0x7fb6290ca8b0, old_table=0x7fb5b4e1cfa0, new_table=0x7fb5b4e129b0, online=true, indexes=0x7fb5b4345f68, key_numbers=0x7fb5b4345f78, n_indexes=2, table=0x7fb5b40040c0, add_cols=0x7fb5b4e16878, col_map=0x7fb5b4e18a70, add_autoinc=18446744073709551615, sequence=..., skip_pk_sort=true, stage=0x7fb5b434bf38) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/storage/innobase/row/row0merge.cc:4384
#14 0x00000000018fa1cd in ha_innobase::inplace_alter_table (this=0x7fb5b4e0e8d0, altered_table=0x7fb5b40040c0, ha_alter_info=0x7fb6162e15e0) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/storage/innobase/handler/handler0alter.cc:5587
#15 0x0000000001518cff in handler::ha_inplace_alter_table (this=0x7fb5b4e0e8d0, altered_table=0x7fb5b40040c0, ha_alter_info=0x7fb6162e15e0) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/handler.h:3247
#16 0x0000000001510b64 in mysql_inplace_alter_table (thd=0x7fb5b40123d0, table_list=0x7fb5b4125470, table=0x7fb5b40159a0, altered_table=0x7fb5b40040c0, ha_alter_info=0x7fb6162e15e0, inplace_supported=HA_ALTER_INPLACE_NO_LOCK_AFTER_PREPARE, target_mdl_request=0x7fb6162e1f70, alter_ctx=0x7fb6162e0b40) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/sql_table.cc:7139
#17 0x00000000015158ce in mysql_alter_table (thd=0x7fb5b40123d0, new_db=0x7fb5b41259f8 "test", new_name=0x0, create_info=0x7fb6162e2a20, table_list=0x7fb5b4125470, alter_info=0x7fb6162e2b10) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/sql_table.cc:9111
#18 0x00000000016735db in Sql_cmd_alter_table::execute (this=0x7fb5b4125ae0, thd=0x7fb5b40123d0) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/sql_alter.cc:316
#19 0x000000000148368e in mysql_execute_command (thd=0x7fb5b40123d0) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/sql_parse.cc:4549
#20 0x00000000014857a5 in mysql_parse (thd=0x7fb5b40123d0, parser_state=0x7fb6162e4500) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/sql_parse.cc:5255
#21 0x000000000147a35f in dispatch_command (thd=0x7fb5b40123d0, com_data=0x7fb6162e4d90, command=COM_QUERY) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/sql_parse.cc:1272
#22 0x0000000001478bc5 in do_command (thd=0x7fb5b40123d0) at /export/home2/tmp/olav/mysql2/vi-5.7-tmp/sql/sql_parse.cc:852

How to repeat:
Run the following test repeatedly. For me it crashes on one out of three runs.

CREATE TABLE t1 (
  col1 INTEGER NOT NULL,
  col2 INTEGER NOT NULL,
  gcol1 INTEGER GENERATED ALWAYS AS (col1 + col2) VIRTUAL,
  col3 INTEGER NOT NULL,
  col4 INTEGER NOT NULL,
  col5 INTEGER DEFAULT NULL,
  col6 INTEGER DEFAULT NULL,
  col7 INTEGER DEFAULT NULL,
  col8 INTEGER DEFAULT NULL,
  col9 INTEGER DEFAULT NULL,
  col10 INTEGER DEFAULT NULL,
  col11 INTEGER DEFAULT NULL,
  col12 INTEGER DEFAULT NULL,
  col13 INTEGER DEFAULT NULL,
  col14 INTEGER DEFAULT NULL,
  col15 INTEGER DEFAULT NULL,
  col16 INTEGER DEFAULT NULL,
  col17 INTEGER DEFAULT NULL,
  col18 INTEGER DEFAULT NULL,
  col19 INTEGER DEFAULT NULL,
  col20 INTEGER DEFAULT NULL,
  col21 INTEGER DEFAULT NULL,
  col22 INTEGER DEFAULT NULL,
  col23 INTEGER DEFAULT NULL,
  col24 INTEGER DEFAULT NULL,
  col25 INTEGER DEFAULT NULL,
  col26 INTEGER DEFAULT NULL,
  col27 INTEGER DEFAULT NULL,
  col28 INTEGER DEFAULT NULL,
  col29 INTEGER DEFAULT NULL,
  col30 INTEGER DEFAULT NULL,
  col31 INTEGER DEFAULT NULL,
  col32 INTEGER DEFAULT NULL,
  col33 INTEGER DEFAULT NULL,
  col34 INTEGER DEFAULT NULL,
  col35 INTEGER DEFAULT NULL,
  col36 INTEGER DEFAULT NULL,
  col37 INTEGER DEFAULT NULL,
  col38 INTEGER DEFAULT NULL,
  col39 INTEGER DEFAULT NULL,
  col40 INTEGER DEFAULT NULL,
  col41 INTEGER DEFAULT NULL,
  col42 INTEGER DEFAULT NULL,
  col43 INTEGER DEFAULT NULL,
  col44 INTEGER DEFAULT NULL,
  col45 INTEGER DEFAULT NULL,
  col46 INTEGER DEFAULT NULL,
  col47 INTEGER DEFAULT NULL,
  col48 INTEGER DEFAULT NULL,
  col49 INTEGER DEFAULT NULL,
  col50 INTEGER DEFAULT NULL,
  col51 INTEGER DEFAULT NULL,
  col52 INTEGER DEFAULT NULL,
  col53 INTEGER DEFAULT NULL,
  col54 INTEGER DEFAULT NULL,
  col55 INTEGER DEFAULT NULL,
  col56 INTEGER DEFAULT NULL,
  col57 INTEGER DEFAULT NULL,
  col58 INTEGER DEFAULT NULL,
  col59 INTEGER DEFAULT NULL,
  col60 INTEGER DEFAULT NULL,
  col61 INTEGER DEFAULT NULL,
  col62 INTEGER DEFAULT NULL,
  col63 INTEGER DEFAULT NULL,
  col64 INTEGER DEFAULT NULL,
  col65 INTEGER DEFAULT NULL,
  gcol2 INTEGER GENERATED ALWAYS AS (col3 / col4) VIRTUAL,
  KEY idx1 (gcol1)
);

INSERT INTO t1 (col1, col2, col3, col4)
  VALUES (1,1,1,1), (2,2,2,2), (3,3,3,3), (4,4,4,4), (5,5,5,5);

SELECT gcol1 FROM t1 FORCE INDEX(idx1);

ALTER TABLE t1 ADD COLUMN extra INTEGER;

SELECT gcol1 FROM t1 FORCE INDEX(idx1);

DROP TABLE t1;
[20 Jul 2015 14:54] Paul DuBois
Noted in 5.7.9, 5.8.0 changelogs.

ALTER TABLE could raise an assertion for a table with an indexed
virtual column having a column position greater than 64.