Skip to content

Instantly share code, notes, and snippets.

@nileema
Created July 8, 2014 19:53
Show Gist options
  • Save nileema/71d0099d804a10cb172b to your computer and use it in GitHub Desktop.
Save nileema/71d0099d804a10cb172b to your computer and use it in GitHub Desktop.
SELECT * FROM (SELECT row_number() over() rn, orderkey, orderstatus, custkey from orders) where rn < 10
- Output[rn, orderkey, orderstatus, custkey]
rn := row_1
- Window[] => [orderkey:bigint, custkey:bigint, orderstatus:varchar, row_1:bigint]
row_1 := row_number()
- Limit[9] => [orderkey:bigint, custkey:bigint, orderstatus:varchar]
- TableScan[local:tpch:orders:sf0.01, original constraint=true] => [orderkey:bigint, custkey:bigint, orderstatus:varchar]
orderkey := local:tpch:orderkey:0
custkey := local:tpch:custkey:1
orderstatus := local:tpch:orderstatus:2
SELECT * FROM (SELECT row_number() over(partition by orderstatus) rn, orderkey, orderstatus, custkey from orders) where rn < 10
- Output[rn, orderkey, orderstatus, custkey]
rn := row_1
- RowNumberLimit[partition by (orderstatus) limit=9] => [orderkey:bigint, custkey:bigint, orderstatus:varchar, row_1:bigint]
row_1 := row_number()
- TableScan[local:tpch:orders:sf0.01, original constraint=true] => [orderkey:bigint, custkey:bigint, orderstatus:varchar]
orderkey := local:tpch:orderkey:0
custkey := local:tpch:custkey:1
orderstatus := local:tpch:orderstatus:2
SELECT * FROM (SELECT row_number() over(order by orderkey) rn, orderkey, orderstatus, custkey from orders) where rn < 10
- Output[rn, orderkey, orderstatus, custkey]
rn := row_1
- Window[order by (orderkey ASC_NULLS_LAST)] => [orderkey:bigint, custkey:bigint, orderstatus:varchar, row_1:bigint]
row_1 := row_number()
- TopN[9 by (orderkey ASC_NULLS_LAST)] => [orderkey:bigint, custkey:bigint, orderstatus:varchar]
- TableScan[local:tpch:orders:sf0.01, original constraint=true] => [orderkey:bigint, custkey:bigint, orderstatus:varchar]
orderkey := local:tpch:orderkey:0
custkey := local:tpch:custkey:1
orderstatus := local:tpch:orderstatus:2
SELECT * FROM (SELECT row_number() over(partition by orderstatus order by orderkey) rn, orderkey, orderstatus, custkey from orders) where rn < 10
- Output[rn, orderkey, orderstatus, custkey]
rn := row_1
- TopNRowNumber[partition by (orderstatus), order by (orderkey ASC_NULLS_LAST) limit 9] => [orderkey:bigint, custkey:bigint, orderstatus:varchar, row_1:bigint]
row_1 := row_number()
- TableScan[local:tpch:orders:sf0.01, original constraint=true] => [orderkey:bigint, custkey:bigint, orderstatus:varchar]
orderkey := local:tpch:orderkey:0
custkey := local:tpch:custkey:1
orderstatus := local:tpch:orderstatus:2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment