[MDEV-17087] Crash on with/window functions Created: 2018-08-28  Updated: 2018-09-11  Resolved: 2018-09-11

Status: Closed
Project: MariaDB Server
Component/s: N/A
Affects Version/s: 10.3.9
Fix Version/s: 10.2.18, 10.3.10

Type: Bug Priority: Major
Reporter: Aria Stewart Assignee: Alice Sherepa
Resolution: Duplicate Votes: 0
Labels: None
Environment:

centos 7.4


Attachments: File crashy2.sql     File schema.sql    
Issue Links:
Relates
relates to MDEV-16992 Assertion `table_ref->table || table_... Closed

 Description   

Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: This could be because you hit a bug. It is also possible that this binary
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: or one of the libraries it was linked against is corrupt, improperly built,
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: or misconfigured. This error can also be caused by malfunctioning hardware.
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: To report this bug, see https://mariadb.com/kb/en/reporting-bugs
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: We will try our best to scrape up some info that will hopefully help
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: diagnose the problem, but since we have already crashed,
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: something is definitely wrong and this may fail.
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: Server version: 10.3.9-MariaDB
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: key_buffer_size=134217728
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: read_buffer_size=131072
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: max_used_connections=1
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: max_threads=153
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: thread_count=10
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: It is possible that mysqld could use up to
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 467396 K  bytes of memory
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: Hope that's ok; if not, decrease some variables in the equation.
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: Thread pointer: 0x7f5bf40009a8
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: Attempting backtrace. You can use the following information to find out
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: where mysqld died. If you see no messages after this, something went
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: terribly wrong...
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: stack_bottom = 0x7f5c90664d00 thread_stack 0x49000
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: *** buffer overflow detected ***: /usr/sbin/mysqld terminated
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: ======= Backtrace: =========
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /lib64/libc.so.6(__fortify_fail+0x37)[0x7f672522f6e7]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /lib64/libc.so.6(+0x116862)[0x7f672522d862]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /lib64/libc.so.6(+0x118647)[0x7f672522f647]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(my_addr_resolve+0xda)[0x5614e5aec17a]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(my_print_stacktrace+0x1c2)[0x5614e5ad5802]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(handle_fatal_signal+0x357)[0x5614e5565f37]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /lib64/libpthread.so.0(+0xf6d0)[0x7f6726e796d0]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z19find_field_in_tableP3THDP5TABLEPKcmbPj+0x1d)[0x5614e533a75d]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z23find_field_in_table_refP3THDP10TABLE_LISTPKcmS4_S4_S4_PP4ItembbPjbPS2_+0x774)[0x5614e533b0a4]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z20find_field_in_tablesP3THDP10Item_identP10TABLE_LISTS4_PP4Item27find_item_error_report_typebb+0x2cc)[0x5614e533b5ec]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN10Item_field10fix_fieldsEP3THDPP4Item+0x317)[0x5614e558ac97]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN9Item_func10fix_fieldsEP3THDPP4Item+0x13f)[0x5614e55d153f]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z13setup_on_exprP3THDP10TABLE_LISTb+0x1c0)[0x5614e533d9b0]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z11setup_condsP3THDP10TABLE_LISTR4ListIS1_EPP4Item+0x19e)[0x5614e533dbde]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN4JOIN7prepareEP10TABLE_LISTjP4ItemjP8st_orderbS5_S3_S5_P13st_select_lexP18st_select_lex_unit+0x4c9)[0x5614e53db209]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN18st_select_lex_unit12prepare_joinEP3THDP13st_select_lexP13select_resultmb+0x113)[0x5614e542a243]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN18st_select_lex_unit7prepareEP10TABLE_LISTP13select_resultm+0xfbd)[0x5614e542dc4d]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z21mysql_derived_prepareP3THDP3LEXP10TABLE_LIST+0x266)[0x5614e535be96]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z20mysql_handle_derivedP3LEXj+0x215)[0x5614e535c845]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z30open_normal_and_derived_tablesP3THDP10TABLE_LISTjj+0x94)[0x5614e533a6b4]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN18Prepared_statement7prepareEPKcj+0x673)[0x5614e53a8c33]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN18Prepared_statement17execute_immediateEPKcj+0x66)[0x5614e53acf16]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z32mysql_sql_stmt_execute_immediateP3THD+0x1c3)[0x5614e53ad173]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x2dfa)[0x5614e539313a]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN13sp_instr_stmt9exec_coreEP3THDPj+0x36)[0x5614e52ff366]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN13sp_lex_keeper23reset_lex_and_exec_coreEP3THDPjbP8sp_instr+0x99)[0x5614e5306e19]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN13sp_instr_stmt7executeEP3THDPj+0x63b)[0x5614e530785b]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN7sp_head7executeEP3THDb+0x860)[0x5614e5302cf0]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN7sp_head17execute_procedureEP3THDP4ListI4ItemE+0x74d)[0x5614e5303f0d]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(+0x5a3039)[0x5614e5389039]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(+0x5a4566)[0x5614e538a566]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN12Sql_cmd_call7executeEP3THD+0x90)[0x5614e538ad80]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_Z21mysql_execute_commandP3THD+0x1585)[0x5614e53918c5]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN13sp_instr_stmt9exec_coreEP3THDPj+0x36)[0x5614e52ff366]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN13sp_lex_keeper23reset_lex_and_exec_coreEP3THDPjbP8sp_instr+0x99)[0x5614e5306e19]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN13sp_instr_stmt7executeEP3THDPj+0x63b)[0x5614e530785b]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN7sp_head7executeEP3THDb+0x860)[0x5614e5302cf0]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(_ZN7sp_head17execute_procedureEP3THDP4ListI4ItemE+0x74d)[0x5614e5303f0d]
Aug 28 22:02:47 ip-10-0-192-142.ec2.internal mysqld[26776]: /usr/sbin/mysqld(+0x5a3039)[0x5614e5389039]



 Comments   
Comment by Aria Stewart [ 2018-08-28 ]

crashy2.sql

Comment by Alice Sherepa [ 2018-08-29 ]

Please add table structures for the tables, involved in the query.

SHOW CREATE TABLE mv_catalog_product_entity_attribute;
SHOW CREATE TABLE catalog_product_entity;
SHOW CREATE TABLE catalog_product_website;
SHOW CREATE TABLE core_store;
SHOW CREATE TABLE mv_product_heirarchy_groupings;
SHOW CREATE TABLE including_tests;

Comment by Aria Stewart [ 2018-08-30 ]

schema.sql Schema attached.

SHOW CREATE TABLE including_tests;

does not apply, as it is in the WITH clause of crashy2.sql

Comment by Alice Sherepa [ 2018-08-31 ]

you are right, sorry.
When I try to reproduce this bug, I get MDEV-16992 or MDEV-17107 (maybe it is the same problem), but was not able to reproduce it with the exact stacktrace. Could you please describe more, how the query was executed, where prepared statements are used,...

Comment by Aria Stewart [ 2018-08-31 ]

Hmm. I was actually triggering the SELECT in a stored procedure to materialize views:

 DEFINER=`aria`@`%` PROCEDURE `materialize_view_as`(view_name varchar(255), target_name varchar(255))
    SQL SECURITY INVOKER
BEGIN
    DECLARE ncol_table INTEGER;
    DECLARE old_sql_mode TEXT;
 
    DECLARE EXIT HANDLER FOR SQLEXCEPTION BEGIN
        ROLLBACK;
        RESIGNAL;
    END;
 
    SET @refreshed_at = NOW();
    SET old_sql_mode = @@sql_mode;
 
    IF EXISTS (SELECT 1 FROM view_sql_modes WHERE table_name = view_name) THEN
        SET @@sql_mode = (SELECT sql_mode FROM view_sql_modes WHERE table_name = view_name);
    END IF;
 
    START TRANSACTION;
 
    SET ncol_table = (SELECT count(*) FROM information_schema.columns WHERE table_schema = SCHEMA() AND table_name = target_name AND column_name != 'refreshed_at');
 
    IF ncol_table = 0 THEN
        EXECUTE IMMEDIATE CONCAT("CREATE TABLE `", target_name, "` AS SELECT *, @refreshed_at AS refreshed_at FROM `", view_name, "`");
    ELSEIF EXISTS (
        SELECT * FROM
            (SELECT column_name FROM information_schema.columns WHERE table_schema = SCHEMA() AND (table_name = view_name OR table_name = target_name)) AS c
            LEFT JOIN
            (SELECT column_name, is_nullable FROM information_schema.columns WHERE table_schema = SCHEMA() AND table_name = target_name) AS mv
                ON mv.column_name = c.column_name
            RIGHT JOIN
            (SELECT column_name FROM information_schema.columns WHERE table_schema = SCHEMA() AND table_name = view_name) AS v
                ON v.column_name = c.column_name
            WHERE mv.column_name IS NULL
                OR (mv.column_name != 'refreshed_at' AND mv.is_nullable = 'NO' AND v.column_name IS NULL)
    ) THEN
        SET @message = CONCAT('Table `', target_name, '` already exists but schema does not match view `', view_name, '`.');
        SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @message;
    ELSE
        EXECUTE IMMEDIATE CONCAT("REPLACE INTO `", target_name, "` SELECT *, @refreshed_at AS refreshed_at FROM `", view_name, "`");
        EXECUTE IMMEDIATE CONCAT("DELETE FROM `", target_name, "` WHERE refreshed_at != @refreshed_at");
    END IF;
 
    REPLACE INTO materialized_view_state(view_name, last_refresh) VALUES (view_name, @refreshed_at);
 
    COMMIT;
 
    SET @@sql_mode = old_sql_mode;
END

Comment by Alice Sherepa [ 2018-09-03 ]

The closest one, that I got:

sql/sql_base.cc:5708(find_field_in_table(THD*, TABLE*, char const*, unsigned long, bool, unsigned int*))[0x5637473aaa32]
sql/sql_base.cc:5866(find_field_in_table_ref(THD*, TABLE_LIST*, char const*, unsigned long, char const*, char const*, char const*, Item**, bool, bool, unsigned int*, bool, TABLE_LIST**))[0x5637473af443]
sql/sql_base.cc:6168(find_field_in_tables(THD*, Item_ident*, TABLE_LIST*, TABLE_LIST*, Item**, find_item_error_report_type, bool, bool))[0x5637473af864]
sql/item.cc:6151(Item_field::fix_fields(THD*, Item**))[0x5637475d876b]
sql/item_func.cc:363(Item_func::fix_fields(THD*, Item**))[0x56374760dbcf]
sql/item.h:826(Item::fix_fields_if_needed_for_scalar(THD*, Item**))[0x5637473ab8af]
sql/sql_base.cc:8118(setup_conds(THD*, TABLE_LIST*, List<TABLE_LIST>&, Item**))[0x5637473abadc]
sql/sql_select.cc:647(setup_without_group)[0x56374743d197]
sql/sql_union.cc:667(st_select_lex_unit::prepare_join(THD*, st_select_lex*, select_result*, unsigned long, bool))[0x56374748d1f5]
sql/sql_union.cc:977(st_select_lex_unit::prepare(TABLE_LIST*, select_result*, unsigned long))[0x56374748fd9a]
sql/sql_derived.cc:766(mysql_derived_prepare(THD*, LEX*, TABLE_LIST*))[0x5637473cbf9a]
sql/sql_derived.cc:104(mysql_handle_derived(LEX*, unsigned int))[0x5637473cb4fe]
sql/sql_base.cc:5012(open_normal_and_derived_tables(THD*, TABLE_LIST*, unsigned int, unsigned int))[0x5637473aa6b4]
sql/sql_prepare.cc:2027(mysql_test_create_view)[0x563747414ec4]
sql/sql_prepare.cc:4877(Prepared_statement::execute_immediate(char const*, unsigned int))[0x563747417244]
sql/sql_prepare.cc:2880(mysql_sql_stmt_execute_immediate(THD*))[0x563747417476]
sql/sql_parse.cc:3774(mysql_execute_command(THD*))[0x5637473fcae6]
sql/sql_class.h:1809(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x563747402fc9]
sql/sql_parse.cc:1850(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x56374740504a]
sql/sql_parse.cc:1397(do_command(THD*))[0x5637474057ce]
sql/sql_connect.cc:1402(do_handle_one_connection(CONNECT*))[0x5637474cbdaf]
sql/sql_connect.cc:1310(handle_one_connection)[0x5637474cbed4]
/lib/x86_64-linux-gnu/libpthread.so.0(+0x76ba)[0x7f01f58696ba]
x86_64/clone.S:111(clone)[0x7f01f46ce41d]

with test case

CREATE TABLE t1 (
  eid int  ,
  entity_type_id int  ,
  t4ibute_set_id int  ,
  type_id varchar(32) ,
  sku varchar(32) ,
  has_options smallint(6) ,
  required_options int  ,
  created_at timestamp NULL ,
  updated_at timestamp NULL 
) ENGINE=InnoDB ;
 
insert into t1 
select seq,seq,seq,'grouped',"varchar",seq,seq,now(),now() from seq_1_to_100;
 
 CREATE TABLE t2 (
  product_id int  ,
  website_id int  
) ENGINE=InnoDB  ;
 
 insert into t2 select seq,seq from seq_1_to_10;
 
CREATE TABLE t3 (
  id int  ,
  code varchar(32) ,
  website_id int  ,
  group_id int  ,
  name varchar(255),
  sort_order int  ,
  is_active int  
) ENGINE=InnoDB ;
 
insert into t3 
select seq,CONCAT("varchar",seq),seq,seq,"varchar",seq,seq from seq_1_to_10;
 
CREATE TABLE t4 (
    eid int  NOT NULL,
    id int(5) NOT NULL,
    c1 varchar(255) NOT NULL,
    i1 int(11),
    v1 varchar(255),
    d1 datetime,
    text_value text,
    decimal_value decimal(12,4),
    refreshed_at timestamp NOT NULL
);
 
insert into t4 select seq  ,0, "visibility", seq, "varchar", now(), "text", seq, now() from seq_1_to_10;
 
 
CREATE TABLE t5 (
  maker_id int ,
  maker_sku varchar(32),
  parent_id int ,
  parent_sku varchar(32),
  parent_type varchar(32),
  eid int ,
  entity_sku varchar(32),
  entity_type varchar(32),
  refreshed_at longtext
) ENGINE=InnoDB ;
 
insert into t5 select seq, "varchar", seq, "varchar","varchar" , seq,"varchar","varchar","longtext" from seq_1_to_10;
 
EXECUTE IMMEDIATE "CREATE view v_maker AS WITH cte1 AS
  ( SELECT DISTINCT t1.eid AS maker_id, t1.sku AS maker_sku, 1 AS is_visible FROM t1 
   JOIN (SELECT DISTINCT maker_id, maker_sku, eid FROM t5) AS heir on  t1.eid=heir.eid),
 
ranked AS
  ( SELECT maker_id, RANK() OVER (PARTITION BY maker_id ORDER BY is_visible DESC, maker_id ASC) AS rank FROM cte1 )
 
SELECT * FROM ranked WHERE rank = 1;";

It is not repeatable after commit d8b8079e421a7d19d3e0c2c4e4a by Igor Babaev "EV-16992 Assertion `table_ref->table || table_ref->view' failed"
If the problem persists in 10.3.10, please comment here and this case will be investigated further.

Generated at Thu Feb 08 08:33:49 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.