Skip to content

Window function row_number() result out of order #2620

@blackstar-baba

Description

@blackstar-baba

Describe the bug

if use order by clause in select sql like this:

select row_number() over(partition by sensorId order by temp),temp,ts from 'readings' where sensorId = 5109 order by temp;

the result out of order

 row_number |        temp        |             ts             
------------+--------------------+----------------------------
        582 | 15.004434478999105 | 2019-11-25 21:29:54.200000
        497 |  15.02493720762422 | 2019-11-20 17:06:55.200000

To reproduce

  1. run this sql
select row_number() over(partition by sensorId order by temp),temp,ts from 'readings' where sensorId = 5109 order by temp;
  1. return result
row_number |        temp        |             ts             
------------+--------------------+----------------------------
        582 | 15.004434478999105 | 2019-11-25 21:29:54.200000
        497 |  15.02493720762422 | 2019-11-20 17:06:55.200000
         28 | 15.027997591584324 | 2019-10-19 07:09:02.300000
         90 | 15.046235126104243 | 2019-10-23 07:44:49.800000
        396 | 15.047976089120429 | 2019-11-14 07:48:38.600000
        573 | 15.052348178001584 | 2019-11-24 21:35:39.700000
         69 | 15.059114960868015 | 2019-10-21 22:11:40.600000
        700 | 15.080164510482806 | 2019-12-04 20:56:32.900000
        727 | 15.081847565313176 | 2019-12-07 06:20:40.500000
        776 | 15.096766057248669 | 2019-12-10 22:21:52.300000
        754 | 15.097841725312733 | 2019-12-08 22:01:43.700000

Expected Behavior

return result

row_number |        temp        |             ts             
------------+--------------------+----------------------------
          0 | 15.004434478999105 | 2019-11-25 21:29:54.200000
          1 |  15.02493720762422 | 2019-11-20 17:06:55.200000
          2 | 15.027997591584324 | 2019-10-19 07:09:02.300000
          3 | 15.046235126104243 | 2019-10-23 07:44:49.800000
          4 | 15.047976089120429 | 2019-11-14 07:48:38.600000
          5 | 15.052348178001584 | 2019-11-24 21:35:39.700000
          6 | 15.059114960868015 | 2019-10-21 22:11:40.600000
          7 | 15.080164510482806 | 2019-12-04 20:56:32.900000
          8 | 15.081847565313176 | 2019-12-07 06:20:40.500000
          9 | 15.096766057248669 | 2019-12-10 22:21:52.300000
         10 | 15.097841725312733 | 2019-12-08 22:01:43.700000
         11 | 15.104586453742463 | 2019-12-19 13:33:19.700000

Environment

- **QuestDB version**: main
- **OS**: MacOS
- **Browser**: Chrome

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIncorrect or unexpected behaviorSQLIssues or changes relating to SQL execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions