diff --git a/pkg/internal/sqlsmith/relational.go b/pkg/internal/sqlsmith/relational.go index 509c0a3ca3ee..650e81eba1ba 100644 --- a/pkg/internal/sqlsmith/relational.go +++ b/pkg/internal/sqlsmith/relational.go @@ -515,6 +515,16 @@ func (s *Smither) randDirection() tree.Direction { return orderDirections[s.rnd.Intn(len(orderDirections))] } +var nullsOrders = []tree.NullsOrder{ + tree.DefaultNullsOrder, + tree.NullsFirst, + tree.NullsLast, +} + +func (s *Smither) randNullsOrder() tree.NullsOrder { + return nullsOrders[s.rnd.Intn(len(nullsOrders))] +} + var nullabilities = []tree.Nullability{ tree.NotNull, tree.Null, @@ -772,7 +782,8 @@ func makeSelect(s *Smither) (tree.Statement, bool) { } order[i] = &tree.Order{ Expr: expr, - NullsOrder: tree.NullsFirst, + Direction: s.randDirection(), + NullsOrder: s.randNullsOrder(), } } stmt = &tree.Select{ @@ -1277,8 +1288,9 @@ func (s *Smither) makeOrderBy(refs colRefs) tree.OrderBy { continue } ob = append(ob, &tree.Order{ - Expr: ref.item, - Direction: s.randDirection(), + Expr: ref.item, + Direction: s.randDirection(), + NullsOrder: s.randNullsOrder(), }) } return ob diff --git a/pkg/internal/sqlsmith/scalar.go b/pkg/internal/sqlsmith/scalar.go index 3cd6c63747bd..9450f96b51cb 100644 --- a/pkg/internal/sqlsmith/scalar.go +++ b/pkg/internal/sqlsmith/scalar.go @@ -462,7 +462,9 @@ func makeFunc(s *Smither, ctx Context, typ *types.T, refs colRefs) (tree.TypedEx orderTypes []*types.T ) addOrdCol := func(expr tree.Expr, typ *types.T) { - order = append(order, &tree.Order{Expr: expr, Direction: s.randDirection()}) + order = append(order, &tree.Order{ + Expr: expr, Direction: s.randDirection(), NullsOrder: s.randNullsOrder(), + }) orderTypes = append(orderTypes, typ) } s.sample(len(refs)-len(parts), 2, func(i int) { @@ -520,7 +522,9 @@ func makeFunc(s *Smither, ctx Context, typ *types.T, refs colRefs) (tree.TypedEx funcExpr.AggType = tree.GeneralAgg funcExpr.OrderBy = make(tree.OrderBy, len(args)) for i := range funcExpr.OrderBy { - funcExpr.OrderBy[i] = &tree.Order{Expr: args[i], Direction: s.randDirection()} + funcExpr.OrderBy[i] = &tree.Order{ + Expr: args[i], Direction: s.randDirection(), NullsOrder: s.randNullsOrder(), + } } } }