Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unknown column with aggregation inside derived table #16367

Closed
systay opened this issue Jul 11, 2024 · 0 comments · Fixed by #16366
Closed

unknown column with aggregation inside derived table #16367

systay opened this issue Jul 11, 2024 · 0 comments · Fixed by #16366

Comments

@systay
Copy link
Collaborator

systay commented Jul 11, 2024

For the query:

select u.id, u.name, t.num_segments from (select id, count(*) as num_segments from user group by 1 order by 2 desc limit 20) t join unsharded u on u.id = t.id

We produce the following plan:

{
  "OperatorType": "Join",
  "Variant": "Join",
  "JoinColumnIndexes": "R:0,R:1,L:0",
  "JoinVars": {
    "t_id": 1
  },
  "TableName": "`user`_unsharded",
  "Inputs": [
    {
      "OperatorType": "Limit",
      "Count": "20",
      "Inputs": [
        {
          "OperatorType": "Route",
          "Variant": "Scatter",
          "Keyspace": {
            "Name": "user",
            "Sharded": true
          },
          "FieldQuery": "select t.num_segments, t.id, count(*) from `user` where 1 != 1 group by id",
          "OrderBy": "2 DESC",
          "Query": "select t.num_segments, t.id, count(*) from `user` group by id order by count(*) desc limit 20",
          "Table": "`user`"
        }
      ]
    },
    {
      "OperatorType": "Route",
      "Variant": "Unsharded",
      "Keyspace": {
        "Name": "main",
        "Sharded": false
      },
      "FieldQuery": "select u.id, u.`name` from unsharded as u where 1 != 1",
      "Query": "select u.id, u.`name` from unsharded as u where u.id = :t_id",
      "Table": "unsharded"
    }
  ]
}

The issue is with this line:

select t.num_segments, t.id, count(*) from `user` group by id order by count(*) desc limit 20

The derived table t doesn't exist, so this query errors out with:

target: xyz.-24.replica: vttablet: rpc error: code = NotFound desc = Unknown column 't.num_segments' in 'field list' (errno 1054)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant