Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <harshit@planetscale.com>
  • Loading branch information
harshit-gangal committed Jun 5, 2024
1 parent 88e075b commit 7e37e48
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
13 changes: 6 additions & 7 deletions go/vt/vtgate/planbuilder/operators/horizon_expanding.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,19 @@ func expandSelectHorizon(ctx *plancontext.PlanningContext, horizon *Horizon, sel
}

func expandOrderBy(ctx *plancontext.PlanningContext, op Operator, qp *QueryProjection) Operator {
proj := newAliasedProjection(op)
var newOrder []OrderBy
sqc := &SubQueryBuilder{}
proj, ok := op.(*Projection)
for _, expr := range qp.OrderExprs {
newExpr, subqs := sqc.pullOutValueSubqueries(ctx, expr.SimplifiedExpr, TableID(op), false)
if newExpr == nil {
// no subqueries found, let's move on
newOrder = append(newOrder, expr)
continue
}
if !ok {
panic(vterrors.VT12001("subquery with aggregation in order by"))
}
proj.addSubqueryExpr(aeWrap(newExpr), newExpr, subqs...)
newOrder = append(newOrder, OrderBy{
Inner: &sqlparser.Order{
Expand All @@ -135,13 +138,9 @@ func expandOrderBy(ctx *plancontext.PlanningContext, op Operator, qp *QueryProje
})

}

if len(proj.Columns.GetColumns()) > 0 {
// if we had to project columns for the ordering,
// we need the projection as source
op = proj
if proj != nil {
proj.Source = sqc.getRootOperator(proj.Source, nil)
}

return &Ordering{
Source: op,
Order: newOrder,
Expand Down
12 changes: 11 additions & 1 deletion go/vt/vtgate/planbuilder/operators/query_planning.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,15 @@ func tryPushOrdering(ctx *plancontext.PlanningContext, in *Ordering) (Operator,
return in, NoRewrite
}
}
ap, ok := src.Columns.(AliasedProjections)
if !ok {
return in, NoRewrite
}
for _, projExpr := range ap {
if projExpr.Info != nil {
return in, NoRewrite
}
}
return Swap(in, src, "push ordering under projection")
case *Aggregator:
if !src.QP.AlignGroupByAndOrderBy(ctx) && !overlaps(ctx, in.Order, src.Grouping) {
Expand All @@ -390,11 +399,12 @@ func tryPushOrdering(ctx *plancontext.PlanningContext, in *Ordering) (Operator,
return src, Rewrote("push ordering into outer side of subquery")
case *SubQuery:
outerTableID := TableID(src.Outer)
for _, order := range in.Order {
for idx, order := range in.Order {
deps := ctx.SemTable.RecursiveDeps(order.Inner.Expr)
if !deps.IsSolvedBy(outerTableID) {
return in, NoRewrite
}
in.Order[idx].SimplifiedExpr = rewriteColNameToArgument(ctx, order.SimplifiedExpr, src., src.originalSubquery)

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Region Sharding example using etcd on ubuntu-22.04

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

expected selector or type assertion, found ','

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

expected selector or type assertion, found ','

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Local example using consul on ubuntu-22.04

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Local example using zk2 on ubuntu-22.04

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Local example using etcd on ubuntu-22.04

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_suite)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_stress_suite)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_migrate_vdiff2_convert_tz)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / End-to-End Test

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_basic)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Unit Test (Evalengine_Race)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Backups - E2E

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_vrepl_stress)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old Vtctl

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Unit Test (Race)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_transaction)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_gen4)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (12)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_godriver)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (21)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / End-to-End Test (Race)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_topo_etcd)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Code Coverage

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_readafterwrite)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_topo)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_general_heavy)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_mariadb_to_mysql)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Reparent Old VTTablet

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_queries)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_copy_parallel)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_reservedconn)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_multi_tenant)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtorc)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vschema)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Schema)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (15)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_throttler_topo)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_cellalias)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (13)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_vindex_heavy)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_v2)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_schema)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vstream)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (ers_prs_newfeatures_heavy)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_partial_keyspace)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_across_db_versions)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (22)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_schema_tracker)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_foreign_key_stress)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_tablegc)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (schemadiff_vrepl)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtbackup)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (backup_pitr)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (mysql80)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_scheduler)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Backups - Manual

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_concurrentdml)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtctlbackup_sharded_clustertest_heavy)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_foreignkey_stress)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vttablet_prscomplex)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (onlineddl_revert)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vreplication_partial_movetables_and_materialize)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (xb_backup)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Query Serving (Queries)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (topo_connection_cache)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (xb_recovery)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_unsharded)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (backup_pitr_xtrabackup)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_topo_consul)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (18)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (vtgate_tablet_healthcheck_cache)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run Upgrade Downgrade Test - Online DDL flow

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Unit Test (mysql57)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (tabletmanager_consul)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Unit Test (evalengine_mysql80)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Unit Test (evalengine_mysql57)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Run endtoend tests on Cluster (mysql_server_vault)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Unit Test (mysql80)

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 10

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

syntax error: unexpected comma, expected name or (

Check failure on line 407 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Docker Test Cluster 25

syntax error: unexpected comma, expected name or (
}
src.Outer, in.Source = in, src.Outer
return src, Rewrote("push ordering into outer side of subquery")

Check failure on line 410 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

missing ',' in argument list

Check failure on line 410 in go/vt/vtgate/planbuilder/operators/query_planning.go

View workflow job for this annotation

GitHub Actions / Static Code Checks Etc

missing ',' in argument list
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/testdata/onecase.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[
{
"comment": "Add your test case here for debugging and run go test -run=One.",
"query": "",
"query": "select 1 from user order by (select col from user)+(select col2 from user)",
"plan": {

}
Expand Down

0 comments on commit 7e37e48

Please sign in to comment.