Uploaded image for project: 'MariaDB ColumnStore'
  1. MariaDB ColumnStore
  2. MCOL-4656

Analyse wrong and possibly redundant code in Decimal::integralWideRound

    XMLWordPrintable

Details

    Description

      This code:

                      return Decimal(value,
                                     scale,
                                     precision,
                                     (div.quot < 0) ? div.quot-- : div.quot++);
      

      looks wrong. The increment and decrement happens AFTER the value is passed to the constructor. So the supposed rounding does not actually happen.

      The intended code was most likely as follows:

                      return Decimal(value,
                                     scale,
                                     precision,
                                     (div.quot < 0) ? div.quot - 1 : div.quot + 1);
      

      However, there is a chance that the entire Decimal::integralWideRound() is a dead code.

      This method is used only once in functioncolumn.h in FunctionColumn::getDecimalVal(). This is a snippet:

                  if (scaleMultiplier > 1)
                  {
                      if (scaleDiff > 0)
                      {
                          // WIP MCOL-641 Unconditional overflow check
                          datatypes::MultiplicationNoOverflowCheck mul;
                          mul(decimal.s128Value, scaleMultiplier, decimal.s128Value);
                      }
                      else
                      {
                          decimal = decimal.integralWideRound();
      

      tntnatbry and bar could not find an SQL script which would make the execution enter the branch calling integralWideRound().

      The code should be further analysed what we should do:

      • either remove the redundant method
      • or fix it to perform rounding correctly

      Attachments

        Issue Links

          Activity

            People

              drrtuy Roman
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

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