Skip to content

Commit 571aa28

Browse files
craig[bot]jeffswenson
andcommitted
162341: changefeed: improve oracle used by TestChangefeedRandomExpressions r=jeffswenson a=jeffswenson TestChangefeedRandomExpressions is using standard sql execution as an oracle for the behavior expected by changefeed queries. There is a long allow list of "expected errors" because the oracle's behavior may not match changefeed queries: 1. Sometimes the optimizer may make it possible to execute a query that is semantically invalid, e.g. by optimizing away a branch that would fail to execute. But it should never take a valid query and make it invalid. 2. The vectorized engine and row engine have slightly different semantics that shows up given enough random expressions are tested. Fixes: cockroachdb#162180 Epic: none Release note: none Co-authored-by: Jeff Swenson <jeffswenson@betterthannull.com>
2 parents 75fe72d + 4a6d50c commit 571aa28

File tree

1 file changed

+16
-45
lines changed

1 file changed

+16
-45
lines changed

pkg/ccl/changefeedccl/changefeed_test.go

Lines changed: 16 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,21 @@ func TestChangefeedRandomExpressions(t *testing.T) {
17871787
continue
17881788
}
17891789
whereClausesChecked[where] = struct{}{}
1790-
query = "SELECT array_to_string(IFNULL(array_agg(distinct rowid),'{}'),'|') FROM seed WHERE " + where
1790+
// Disable the optimizer and use the row query execution engine. This
1791+
// helps ensure we avoid cases where the oracle query has different
1792+
// behavior than the internal query. For example, the vectorized engine
1793+
// and optimizer may prevent a `false and crash()` expression from
1794+
// returning an error even though it will fail when the cdc query
1795+
// attempts to execute it.
1796+
//
1797+
// NOTE: DB is a connection pool. We set the options in the statement to
1798+
// ensure they are set on the connection that is actually executing the
1799+
// query. We can't easily use a single connection because when queries
1800+
// timeout, the context cancellation closes the connection.
1801+
query = `
1802+
SET testing_optimizer_disable_rule_probability = 1.0;
1803+
SET vectorize = off;
1804+
SELECT array_to_string(IFNULL(array_agg(distinct rowid),'{}'),'|') FROM seed WHERE ` + where
17911805
t.Log(query)
17921806
timeoutCtx, cancel := context.WithTimeout(context.Background(), time.Second*2)
17931807
rows := s.DB.QueryRowContext(timeoutCtx, query)
@@ -1819,54 +1833,11 @@ func TestChangefeedRandomExpressions(t *testing.T) {
18191833
}
18201834
err = assertPayloadsBaseErr(context.Background(), seedFeed, assertedPayloads, false, false, nil, changefeedbase.OptEnvelopeWrapped)
18211835
closeFeedIgnoreError(t, seedFeed)
1822-
if err != nil {
1823-
// Skip errors that may come up during SQL execution. If the SQL query
1824-
// didn't fail with these errors, it's likely because the query was built in
1825-
// a way that did not have to execute on the row that caused the error, but
1826-
// the CDC query did.
1827-
// Since we get the error that caused the changefeed job to
1828-
// fail from scraping the job status and creating a new
1829-
// error, we unfortunately don't have the pgcode and have to
1830-
// rely on known strings.
1831-
validPgErrs := []string{
1832-
"argument is not an object",
1833-
"cannot subtract infinite dates",
1834-
"dwithin distance cannot be less than zero",
1835-
"error parsing EWKB",
1836-
"error parsing EWKT",
1837-
"error parsing GeoJSON",
1838-
"expected LineString",
1839-
"geometry type is unsupported",
1840-
"invalid escape string",
1841-
"invalid input syntax for type",
1842-
"invalid regular expression",
1843-
"no locations to init GEOS",
1844-
"parameter has to be of type Point",
1845-
"regexp compilation failed",
1846-
"result out of range",
1847-
"should be of length",
1848-
"unknown DateStyle parameter",
1849-
}
1850-
containsKnownPgErr := func(e error) (interface{}, bool) {
1851-
for _, v := range validPgErrs {
1852-
if strings.Contains(e.Error(), v) {
1853-
return nil, true
1854-
}
1855-
}
1856-
return nil, false
1857-
}
1858-
if _, contains := errors.If(err, containsKnownPgErr); contains {
1859-
t.Logf("Skipping statement %s because it encountered pgerror %s", createStmt, err)
1860-
continue
1861-
}
1862-
1863-
t.Fatal(err)
1864-
}
1836+
require.NoError(t, err)
18651837
numNonTrivialTestRuns++
18661838
}
18671839
require.Greater(t, numNonTrivialTestRuns, 0, "Expected >0 predicates to be nontrivial out of %d attempts", n)
18681840
t.Logf("%d predicates checked: all had the same result in SELECT and CHANGEFEED", numNonTrivialTestRuns)
1869-
18701841
}
18711842

18721843
cdcTest(t, testFn, feedTestForceSink(`kafka`), withAllowChangefeedErr("changefeed may have parsing failure on some queries"))

0 commit comments

Comments
 (0)