Uploaded image for project: 'Phoenix'
  1. Phoenix
  2. PHOENIX-2876

Using aggregation function in ORDER BY

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.7.0
    • 4.8.0
    • None
    • None

    Description

      create table x (id integer primary key, i1 integer, i2 integer);
      upsert into x values (1, 1, 1);
      upsert into x values (2, 2, 2);
      upsert into x values (3, 2, 3);
      upsert into x values (4, 3, 3);
      upsert into x values (5, 3, 2);
      upsert into x values (6, 3, 1);
      

      Test query:

      select i1 from X group by i1 order by avg(i2) desc;
      

      Expected result: 2, 3, 1
      Real result : 1, 3, 2
      In other hands

      select i1, avg(i2) from X group by i1 order by avg(i2) desc;
      

      works correctly.
      That happens because in ORDER BY we add nothing to RowProjector if we deal with aggregate functions. So, there is a question. Do we have any restrictions why we can't add the expression from ORDER BY to RowProjector ?

      Attachments

        1. PHOENIX-2876-2.patch
          14 kB
          Sergey Soldatov
        2. PHOENIX-2876-1.patch
          5 kB
          Sergey Soldatov

        Activity

          People

            sergey.soldatov Sergey Soldatov
            sergey.soldatov Sergey Soldatov
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: