-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: use more interesting values for statement-bundle recreate
This commit introduces a couple of helper methods to `tree` package that extend `tree.Datum.Prev` and `tree.Datum.Next` for certain datum types. Methods of `tree.Datum` interface are pretty strict on some guarantees (like lexicographical ordering), but in some places we don't need such things, yet we want to get a "smaller" or a "larger" datum than any given one if possible. This is now supported by the new utility methods. These methods are now utilized by `debug statement-bundle recreate` command when `--placeholder` options are used in order to generate all possible plans. In one example of a stmt bundle the number of generated plans increased from 14 to 19. This commit additionally improves the relevant code when recreating the bundle a bit. Epic: None Release note: None
- Loading branch information
1 parent
18ecb5d
commit 4d9e721
Showing
5 changed files
with
238 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// Copyright 2023 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package tree_test | ||
|
||
import ( | ||
"math" | ||
"testing" | ||
|
||
"github.com/cockroachdb/apd/v3" | ||
"github.com/cockroachdb/cockroach/pkg/sql/randgen" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/cockroachdb/cockroach/pkg/util/log" | ||
"github.com/cockroachdb/cockroach/pkg/util/randutil" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestDatumPrevNext verifies that tree.DatumPrev and tree.DatumNext return | ||
// datums that are smaller and larger, respectively, than the given datum if | ||
// ok=true is returned (modulo some edge cases). | ||
func TestDatumPrevNext(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
defer log.Scope(t).Close(t) | ||
|
||
rng, _ := randutil.NewTestRand() | ||
var evalCtx eval.Context | ||
const numRuns = 1000 | ||
for i := 0; i < numRuns; i++ { | ||
typ := randgen.RandType(rng) | ||
d := randgen.RandDatum(rng, typ, false /* nullOk */) | ||
// Ignore NaNs and infinities. | ||
if f, ok := d.(*tree.DFloat); ok { | ||
if math.IsNaN(float64(*f)) || math.IsInf(float64(*f), 0) { | ||
continue | ||
} | ||
} | ||
if dec, ok := d.(*tree.DDecimal); ok { | ||
if dec.Form == apd.NaN || dec.Form == apd.Infinite { | ||
continue | ||
} | ||
} | ||
if !d.IsMin(&evalCtx) { | ||
if prev, ok := tree.DatumPrev(d, &evalCtx, &evalCtx.CollationEnv); ok { | ||
cmp, err := d.CompareError(&evalCtx, prev) | ||
require.NoError(t, err) | ||
require.True(t, cmp > 0, "d=%s, prev=%s, type=%s", d.String(), prev.String(), d.ResolvedType().SQLString()) | ||
} | ||
} | ||
if !d.IsMax(&evalCtx) { | ||
if next, ok := tree.DatumNext(d, &evalCtx, &evalCtx.CollationEnv); ok { | ||
cmp, err := d.CompareError(&evalCtx, next) | ||
require.NoError(t, err) | ||
require.True(t, cmp < 0, "d=%s, next=%s, type=%s", d.String(), next.String(), d.ResolvedType().SQLString()) | ||
} | ||
} | ||
} | ||
} |