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

sformat('Num [{:20}]', 42) gives incorrect result in view

Details

    Description

      Test:

      create view v1 as select sformat('Num [{:20}]', 42);
      select * from v1;
      drop view v1;
      

      Expected result:

      Num [                  42]
      

      Actual result:

      Num [   
      

      Attachments

        Issue Links

          Activity

            lstartseva Lena Startseva created issue -
            lstartseva Lena Startseva made changes -
            Field Original Value New Value
            lstartseva Lena Startseva made changes -
            Labels view-protocol
            lstartseva Lena Startseva made changes -
            Assignee Lena Startseva [ JIRAUSER50478 ] Oleksandr Byelkin [ sanja ]

            It is not a problem of view print:

            show create view v1;
            View	Create View	character_set_client	collation_connection
            v1	CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select sformat('Num [{:20}]',42) AS `sformat('Num [{:20}]', 42)`latin1	latin1_swedish_ci
            

            sanja Oleksandr Byelkin added a comment - It is not a problem of view print: show create view v1; View Create View character_set_client collation_connection v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select sformat('Num [{:20}]',42) AS `sformat('Num [{:20}]', 42)`latin1 latin1_swedish_ci
            elenst Elena Stepanova made changes -
            Fix Version/s 10.7 [ 24805 ]
            Fix Version/s 10.8 [ 26121 ]
            Fix Version/s 10.9 [ 26905 ]
            Fix Version/s 10.10 [ 27530 ]
            Fix Version/s 10.11 [ 27614 ]
            Weijun Huang Weijun Huang added a comment -

            create view v1 as select sformat('Num [{:6}]', 42);
            select * from v1;
            sformat('Num [{:6}]', 42)
            Num [    42]
            drop view v1;
            create view v1 as select sformat('Num [{:7}]', 42);
            select * from v1;
            sformat('Num [{:7}]', 42)
            Num [     42
            drop view v1;
            create view v1 as select sformat('Num [{:8}]', 42);
            select * from v1;
            sformat('Num [{:8}]', 42)
            Num [      4
            drop view v1;
            create view v1 as select sformat('Num [{:9}]', 42);
            select * from v1;
            sformat('Num [{:9}]', 42)
            Num [       
            drop view v1;
            main.view_test                           [ pass ]     12
            

            Weijun Huang Weijun Huang added a comment - create view v1 as select sformat( 'Num [{:6}]' , 42 ); select * from v1; sformat( 'Num [{:6}]' , 42 ) Num [ 42 ] drop view v1; create view v1 as select sformat( 'Num [{:7}]' , 42 ); select * from v1; sformat( 'Num [{:7}]' , 42 ) Num [ 42 drop view v1; create view v1 as select sformat( 'Num [{:8}]' , 42 ); select * from v1; sformat( 'Num [{:8}]' , 42 ) Num [ 4 drop view v1; create view v1 as select sformat( 'Num [{:9}]' , 42 ); select * from v1; sformat( 'Num [{:9}]' , 42 ) Num [ drop view v1; main.view_test [ pass ] 12
            Weijun Huang Weijun Huang added a comment -

            I have discovered a bug in `mariadbd` at `Field_varstring::store(this=0x00000001050eb6a0, from="Num [ 42]", length=15, cs=0x0000000101a23f88)` in the `field.cc` file at line 7872, column 3. The issue is that the `Field_varstring.field_length` value, 12, is smaller than the length of the string, which is causing the error. I have attempted to modify the `field_length` parameter to resolve the issue, but I have been unsuccessful so far.

            Weijun Huang Weijun Huang added a comment - I have discovered a bug in `mariadbd` at `Field_varstring::store(this=0x00000001050eb6a0, from="Num [ 42]", length=15, cs=0x0000000101a23f88)` in the `field.cc` file at line 7872, column 3. The issue is that the `Field_varstring.field_length` value, 12, is smaller than the length of the string, which is causing the error. I have attempted to modify the `field_length` parameter to resolve the issue, but I have been unsuccessful so far.
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.7 [ 24805 ]

            Item_func_sformat determines the max length of the result as a sum of max length of its arguments:

            bool Item_func_sformat::fix_length_and_dec(THD *thd)
            {
              ...
              for (uint i=0 ; i < arg_count ; i++)
              {
                char_length+= args[i]->max_char_length();
            

            this, of course, makes little sense, because the length of the result can be anything, depending on the format string.

            serg Sergei Golubchik added a comment - Item_func_sformat determines the max length of the result as a sum of max length of its arguments: bool Item_func_sformat::fix_length_and_dec(THD *thd) { ... for (uint i=0 ; i < arg_count ; i++) { char_length+= args[i]->max_char_length(); this, of course, makes little sense, because the length of the result can be anything, depending on the format string.
            serg Sergei Golubchik made changes -
            Labels view-protocol beginner-friendly view-protocol
            julien.fritsch Julien Fritsch made changes -
            Fix Version/s 10.8 [ 26121 ]
            danblack Daniel Black added a comment -

            Thanks Weijun Huang.

            Note Fix Versions may be incorrect. Merged to 10.8 however bb-10.8-release is created and no alternate version exist in JIRA yet.

            danblack Daniel Black added a comment - Thanks Weijun Huang . Note Fix Versions may be incorrect. Merged to 10.8 however bb-10.8-release is created and no alternate version exist in JIRA yet.
            danblack Daniel Black made changes -
            Component/s Data types [ 13906 ]
            Fix Version/s 10.9.6 [ 28520 ]
            Fix Version/s 10.10.4 [ 28522 ]
            Fix Version/s 10.11.3 [ 28524 ]
            Fix Version/s 11.1.1 [ 28704 ]
            Fix Version/s 10.8.8 [ 28518 ]
            Fix Version/s 11.0.2 [ 28706 ]
            Fix Version/s 10.9 [ 26905 ]
            Fix Version/s 10.10 [ 27530 ]
            Fix Version/s 10.11 [ 27614 ]
            Assignee Oleksandr Byelkin [ sanja ] Daniel Black [ danblack ]
            Resolution Fixed [ 1 ]
            Status Open [ 1 ] Closed [ 6 ]
            dbart Daniel Bartholomew made changes -
            Fix Version/s 10.9.7 [ 28916 ]
            Fix Version/s 10.10.5 [ 28917 ]
            Fix Version/s 10.11.4 [ 28918 ]
            Fix Version/s 10.8.8 [ 28518 ]
            Fix Version/s 10.9.6 [ 28520 ]
            Fix Version/s 10.10.4 [ 28522 ]
            Fix Version/s 10.11.3 [ 28524 ]
            dbart Daniel Bartholomew made changes -
            Fix Version/s 10.9.8 [ 29015 ]
            Fix Version/s 10.10.6 [ 29017 ]
            Fix Version/s 10.11.5 [ 29019 ]
            Fix Version/s 11.0.3 [ 28920 ]
            Fix Version/s 11.1.2 [ 28921 ]
            Fix Version/s 11.1.1 [ 28704 ]
            Fix Version/s 11.0.2 [ 28706 ]
            Fix Version/s 10.9.7 [ 28916 ]
            Fix Version/s 10.10.5 [ 28917 ]
            Fix Version/s 10.11.4 [ 28918 ]

            People

              danblack Daniel Black
              lstartseva Lena Startseva
              Votes:
              0 Vote for this issue
              Watchers:
              5 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.