Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-24160

date_format() mixed with if() in a computed column causes server segfault

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 10.4.14
    • N/A
    • Virtual Columns
    • None
    • Fedora 32

    Description

      I have a table containing two date fields, a text field and a varchar(128) field. I did a

      alter table event add full_event_name text as (concat(
        date_format(event_starts_on, '%Y-%m-%d '),                         
        if(event_starts_on <> event_ends_on, date_format(event_ends_on, 'to %Y-%m-%d '), ''),
        event_location_id, ' ',                                                              
        event_name));
      

      After I did that, accessing the table (say, by doing a mysqldump of its database) causes the server to segfault. If I remove the date_format() calls or the if(), the server doesn't segfault.

      Attachments

        Issue Links

          Activity

            danblack Daniel Black added a comment -

            for completeness can you include the `show create table event` output before the table was altered.

            danblack Daniel Black added a comment - for completeness can you include the `show create table event` output before the table was altered.

            CREATE TABLE `event` (
            `id` int(11) NOT NULL AUTO_INCREMENT,
            `event_name` varchar(128) NOT NULL,
            `event_starts_on` date NOT NULL,
            `event_ends_on` date NOT NULL,
            `event_base_cost` int(10) unsigned NOT NULL CHECK (`event_base_cost` >= 0),
            `event_ceus` int(10) unsigned DEFAULT NULL CHECK (`event_ceus` >= 0),
            `event_notes` longtext DEFAULT NULL,
            `event_type_id` int(11) NOT NULL,
            `event_location_id` varchar(128) NOT NULL,
            PRIMARY KEY (`id`),
            UNIQUE KEY `event_name` (`event_name`),
            KEY `event_event_type_id_49279ad6_fk_eventtype_id` (`event_type_id`),
            KEY `event_event_location_id_b7eff272_fk_event` (`event_location_id`),
            CONSTRAINT `event_event_location_id_b7eff272_fk_event` FOREIGN KEY (`event_location_id`) REFERENCES `eventlocation` (`event_location`),
            CONSTRAINT `event_event_type_id_49279ad6_fk_eventtype_id` FOREIGN KEY (`event_type_id`) REFERENCES `eventtype` (`id`)
            ) ENGINE=InnoDB AUTO_INCREMENT=454 DEFAULT CHARSET=latin1

            dajt Jay Fenlason (Inactive) added a comment - CREATE TABLE `event` ( `id` int(11) NOT NULL AUTO_INCREMENT, `event_name` varchar(128) NOT NULL, `event_starts_on` date NOT NULL, `event_ends_on` date NOT NULL, `event_base_cost` int(10) unsigned NOT NULL CHECK (`event_base_cost` >= 0), `event_ceus` int(10) unsigned DEFAULT NULL CHECK (`event_ceus` >= 0), `event_notes` longtext DEFAULT NULL, `event_type_id` int(11) NOT NULL, `event_location_id` varchar(128) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `event_name` (`event_name`), KEY `event_event_type_id_49279ad6_fk_eventtype_id` (`event_type_id`), KEY `event_event_location_id_b7eff272_fk_event` (`event_location_id`), CONSTRAINT `event_event_location_id_b7eff272_fk_event` FOREIGN KEY (`event_location_id`) REFERENCES `eventlocation` (`event_location`), CONSTRAINT `event_event_type_id_49279ad6_fk_eventtype_id` FOREIGN KEY (`event_type_id`) REFERENCES `eventtype` (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=454 DEFAULT CHARSET=latin1
            danblack Daniel Black added a comment -

            I'm having trouble reproducing this. Maybe its got some element of the data or FK tables related. Can you include the stack trace and a set of data that can reproduce this?

            MariaDB [test]> flush tables;
            Query OK, 0 rows affected (0.001 sec)
             
            MariaDB [test]> alter table event add full_event_name text as (concat(    date_format(event_starts_on, '%Y-%m-%d '),
                          if(event_starts_on <> event_ends_on, date_format(event_ends_on, 'to %Y-%m-%d '), ''),    event_location_id, ' ',
                                                                         event_name));
            Query OK, 0 rows affected (0.004 sec)
            Records: 0  Duplicates: 0  Warnings: 0
             
            MariaDB [test]> flush tables;
            Query OK, 0 rows affected (0.000 sec)
             
            MariaDB [test]> select * from event;
            +-----+------------+-----------------+---------------+-----------------+------------+---------------+---------------+-----------------------------+----------------------------------------------------------------+
            | id  | event_name | event_starts_on | event_ends_on | event_base_cost | event_ceus | event_notes   | event_type_id | event_location_id           | full_event_name                                                |
            +-----+------------+-----------------+---------------+-----------------+------------+---------------+---------------+-----------------------------+----------------------------------------------------------------+
            | 454 | sunday     | 2020-11-08      | 2020-11-08    |              44 |         33 | oh what a day |            42 | somewhere under the rainbow | 2020-11-08 somewhere under the rainbow sunday                  |
            | 455 | stresstime | 2020-11-04      | 2020-11-12    |              44 |         33 | yaya          |            42 | somewhere under the bridge  | 2020-11-04 to 2020-11-12 somewhere under the bridge stresstime |
            +-----+------------+-----------------+---------------+-----------------+------------+---------------+---------------+-----------------------------+----------------------------------------------------------------+
            2 rows in set (0.002 sec)
             
            MariaDB [test]> select version();
            +-----------------+
            | version()       |
            +-----------------+
            | 10.4.14-MariaDB |
            +-----------------+
            1 row in set (0.000 sec)
             
            MariaDB [test]> show create table event\G
            *************************** 1. row ***************************
                   Table: event
            Create Table: CREATE TABLE `event` (
              `id` int(11) NOT NULL AUTO_INCREMENT,
              `event_name` varchar(128) NOT NULL,
              `event_starts_on` date NOT NULL,
              `event_ends_on` date NOT NULL,
              `event_base_cost` int(10) unsigned NOT NULL CHECK (`event_base_cost` >= 0),
              `event_ceus` int(10) unsigned DEFAULT NULL CHECK (`event_ceus` >= 0),
              `event_notes` longtext DEFAULT NULL,
              `event_type_id` int(11) NOT NULL,
              `event_location_id` varchar(128) NOT NULL,
              `full_event_name` text GENERATED ALWAYS AS (concat(date_format(`event_starts_on`,'%Y-%m-%d '),if(`event_starts_on` <> `event_ends_on`,date_format(`event_ends_on`,'to %Y-%m-%d '),''),`event_location_id`,' ',`event_name`)) VIRTUAL,
              PRIMARY KEY (`id`),
              UNIQUE KEY `event_name` (`event_name`),
              KEY `event_event_type_id_49279ad6_fk_eventtype_id` (`event_type_id`),
              KEY `event_event_location_id_b7eff272_fk_event` (`event_location_id`)
            ) ENGINE=InnoDB AUTO_INCREMENT=456 DEFAULT CHARSET=latin1
            1 row in set (0.000 sec)
            

            danblack Daniel Black added a comment - I'm having trouble reproducing this. Maybe its got some element of the data or FK tables related. Can you include the stack trace and a set of data that can reproduce this? MariaDB [test]> flush tables; Query OK, 0 rows affected (0.001 sec)   MariaDB [test]> alter table event add full_event_name text as (concat( date_format(event_starts_on, '%Y-%m-%d '), if(event_starts_on <> event_ends_on, date_format(event_ends_on, 'to %Y-%m-%d '), ''), event_location_id, ' ', event_name)); Query OK, 0 rows affected (0.004 sec) Records: 0 Duplicates: 0 Warnings: 0   MariaDB [test]> flush tables; Query OK, 0 rows affected (0.000 sec)   MariaDB [test]> select * from event; +-----+------------+-----------------+---------------+-----------------+------------+---------------+---------------+-----------------------------+----------------------------------------------------------------+ | id | event_name | event_starts_on | event_ends_on | event_base_cost | event_ceus | event_notes | event_type_id | event_location_id | full_event_name | +-----+------------+-----------------+---------------+-----------------+------------+---------------+---------------+-----------------------------+----------------------------------------------------------------+ | 454 | sunday | 2020-11-08 | 2020-11-08 | 44 | 33 | oh what a day | 42 | somewhere under the rainbow | 2020-11-08 somewhere under the rainbow sunday | | 455 | stresstime | 2020-11-04 | 2020-11-12 | 44 | 33 | yaya | 42 | somewhere under the bridge | 2020-11-04 to 2020-11-12 somewhere under the bridge stresstime | +-----+------------+-----------------+---------------+-----------------+------------+---------------+---------------+-----------------------------+----------------------------------------------------------------+ 2 rows in set (0.002 sec)   MariaDB [test]> select version(); +-----------------+ | version() | +-----------------+ | 10.4.14-MariaDB | +-----------------+ 1 row in set (0.000 sec)   MariaDB [test]> show create table event\G *************************** 1. row *************************** Table: event Create Table: CREATE TABLE `event` ( `id` int(11) NOT NULL AUTO_INCREMENT, `event_name` varchar(128) NOT NULL, `event_starts_on` date NOT NULL, `event_ends_on` date NOT NULL, `event_base_cost` int(10) unsigned NOT NULL CHECK (`event_base_cost` >= 0), `event_ceus` int(10) unsigned DEFAULT NULL CHECK (`event_ceus` >= 0), `event_notes` longtext DEFAULT NULL, `event_type_id` int(11) NOT NULL, `event_location_id` varchar(128) NOT NULL, `full_event_name` text GENERATED ALWAYS AS (concat(date_format(`event_starts_on`,'%Y-%m-%d '),if(`event_starts_on` <> `event_ends_on`,date_format(`event_ends_on`,'to %Y-%m-%d '),''),`event_location_id`,' ',`event_name`)) VIRTUAL, PRIMARY KEY (`id`), UNIQUE KEY `event_name` (`event_name`), KEY `event_event_type_id_49279ad6_fk_eventtype_id` (`event_type_id`), KEY `event_event_location_id_b7eff272_fk_event` (`event_location_id`) ) ENGINE=InnoDB AUTO_INCREMENT=456 DEFAULT CHARSET=latin1 1 row in set (0.000 sec)
            alice Alice Sherepa added a comment -

            Please add error log and your .cnf file(s)

            alice Alice Sherepa added a comment - Please add error log and your .cnf file(s)
            alice Alice Sherepa added a comment -

            dajt, Could you please take a look at MDEV-24176-does it look the same as yours? - I got it, while tried to reproduce this bug, but reported it separately - in case it is different.

            alice Alice Sherepa added a comment - dajt , Could you please take a look at MDEV-24176 -does it look the same as yours? - I got it, while tried to reproduce this bug, but reported it separately - in case it is different.

            @Alice It looks to me like MDEV-24176 is probably the same bug, although I don't think I made any changes to the event table data when I found it. Did you notice that the second "INSERT INTO t1..." would throw an error if it didn't segfault first, because there are now three columns in the table and you only provided two values? But the server segfaults before it gets that far. And if you remove the mysqldump between the first insert and second, it doesn't segfault.

            You've got a nice elegant reproducer there. Should we close this ticket and track the bug under MDEV-24176?

            dajt Jay Fenlason (Inactive) added a comment - @Alice It looks to me like MDEV-24176 is probably the same bug, although I don't think I made any changes to the event table data when I found it. Did you notice that the second "INSERT INTO t1..." would throw an error if it didn't segfault first, because there are now three columns in the table and you only provided two values? But the server segfaults before it gets that far. And if you remove the mysqldump between the first insert and second, it doesn't segfault. You've got a nice elegant reproducer there. Should we close this ticket and track the bug under MDEV-24176 ?
            alice Alice Sherepa added a comment -

            @Jay, Thank you, I am glad to hear it!
            Let's track it there, but in case you will get a problem even after the fix of MDEV-24176- please comment here and we will investigate it further.

            alice Alice Sherepa added a comment - @Jay, Thank you, I am glad to hear it! Let's track it there, but in case you will get a problem even after the fix of MDEV-24176 - please comment here and we will investigate it further.

            People

              Unassigned Unassigned
              dajt Jay Fenlason (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.