diff --git a/pkg/ccl/streamingccl/streamingest/alter_replication_job.go b/pkg/ccl/streamingccl/streamingest/alter_replication_job.go index 16792a3c6477..b6dda8e9aad8 100644 --- a/pkg/ccl/streamingccl/streamingest/alter_replication_job.go +++ b/pkg/ccl/streamingccl/streamingest/alter_replication_job.go @@ -77,7 +77,7 @@ func evalTenantReplicationOptions( r.retention = &retSeconds } if options.ResumeTimestamp != nil { - ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.ResumeTimestamp, op, asof.ReplicationCutover) + ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.ResumeTimestamp, op) if err != nil { return nil, err } @@ -168,7 +168,7 @@ func alterReplicationJobHook( } ct, err := asof.EvalSystemTimeExpr(ctx, evalCtx, p.SemaCtx(), alterTenantStmt.Cutover.Timestamp, - alterReplicationJobOp, asof.ReplicationCutover) + alterReplicationJobOp) if err != nil { return nil, nil, nil, false, err } diff --git a/pkg/sql/logictest/testdata/logic_test/as_of b/pkg/sql/logictest/testdata/logic_test/as_of index a794436c5d97..e026a9fc01ba 100644 --- a/pkg/sql/logictest/testdata/logic_test/as_of +++ b/pkg/sql/logictest/testdata/logic_test/as_of @@ -50,10 +50,10 @@ SELECT * FROM t AS OF SYSTEM TIME follower_read_timestamp('boom') statement error pq: AS OF SYSTEM TIME: only constant expressions, with_min_timestamp, with_max_staleness, or follower_read_timestamp are allowed SELECT * FROM t AS OF SYSTEM TIME now() -statement error pq: AS OF SYSTEM TIME: interval value '10s' too large, AS OF interval must be <= -1µs +statement error pq: request timestamp .* too far in future SELECT * FROM t AS OF SYSTEM TIME '10s' -statement error pq: AS OF SYSTEM TIME: interval value '00:00:00.000001' too large, AS OF interval must be <= -1µs +statement ok SELECT * FROM t AS OF SYSTEM TIME interval '1 microsecond' # Verify that the TxnTimestamp used to generate now() and current_timestamp() is diff --git a/pkg/sql/pgwire/testdata/pgtest/bind_and_resolve b/pkg/sql/pgwire/testdata/pgtest/bind_and_resolve index fd1b86f6bb04..fb2ba3f6b633 100644 --- a/pkg/sql/pgwire/testdata/pgtest/bind_and_resolve +++ b/pkg/sql/pgwire/testdata/pgtest/bind_and_resolve @@ -40,7 +40,7 @@ ReadyForQuery # This is crdb_only because Postgres does not support AS OF SYSTEM TIME. send crdb_only -Query {"String": "BEGIN AS OF SYSTEM TIME '1s'"} +Query {"String": "BEGIN AS OF SYSTEM TIME '0s'"} Sync ---- diff --git a/pkg/sql/sem/asof/as_of.go b/pkg/sql/sem/asof/as_of.go index 853fd36a87ff..f6627af7f1ee 100644 --- a/pkg/sql/sem/asof/as_of.go +++ b/pkg/sql/sem/asof/as_of.go @@ -202,41 +202,16 @@ func Eval( } stmtTimestamp := evalCtx.GetStmtTimestamp() - ret.Timestamp, err = DatumToHLC(evalCtx, stmtTimestamp, d, AsOf) + ret.Timestamp, err = DatumToHLC(evalCtx, stmtTimestamp, d) if err != nil { return eval.AsOfSystemTime{}, errors.Wrap(err, "AS OF SYSTEM TIME") } return ret, nil } -// DatumToHLCUsage specifies which statement DatumToHLC() is used for. -type DatumToHLCUsage int64 - -const ( - // AsOf is when the DatumToHLC() is used for an AS OF SYSTEM TIME statement. - // In this case, if the interval is not synthetic, its value has to be negative - // and last longer than a nanosecond. - AsOf DatumToHLCUsage = iota - // Split is when the DatumToHLC() is used for a SPLIT statement. - // In this case, if the interval is not synthetic, its value has to be positive - // and last longer than a nanosecond. - Split - - // ReplicationCutover is when the DatumToHLC() is used for an - // ALTER VIRTUAL CLUSTER ... COMPLETE REPLICATION statement. - ReplicationCutover - - // ShowTenantFingerprint is when the DatumToHLC() is used for an SHOW - // EXPERIMENTAL_FINGERPRINTS FROM TENANT ... WITH START TIMESTAMP statement. - // - // ShowTenantFingerprint has the same constraints as AsOf, and so we use the - // same value. - ShowTenantFingerprint = AsOf -) - // DatumToHLC performs the conversion from a Datum to an HLC timestamp. func DatumToHLC( - evalCtx *eval.Context, stmtTimestamp time.Time, d tree.Datum, usage DatumToHLCUsage, + evalCtx *eval.Context, stmtTimestamp time.Time, d tree.Datum, ) (hlc.Timestamp, error) { ts := hlc.Timestamp{} var convErr error @@ -257,10 +232,6 @@ func DatumToHLC( if iv, err := tree.ParseDInterval(evalCtx.GetIntervalStyle(), s); err == nil { if (iv.Duration == duration.Duration{}) { convErr = errors.Errorf("interval value %v too small, absolute value must be >= %v", d, time.Microsecond) - } else if (usage == AsOf && iv.Duration.Compare(duration.Duration{}) > 0) { - convErr = errors.Errorf("interval value %v too large, AS OF interval must be <= -%v", d, time.Microsecond) - } else if (usage == Split && iv.Duration.Compare(duration.Duration{}) < 0) { - convErr = errors.Errorf("interval value %v too small, SPLIT AT interval must be >= %v", d, time.Microsecond) } ts.WallTime = duration.Add(stmtTimestamp, iv.Duration).UnixNano() break @@ -275,11 +246,6 @@ func DatumToHLC( case *tree.DDecimal: ts, convErr = hlc.DecimalToHLC(&d.Decimal) case *tree.DInterval: - if (usage == AsOf && d.Duration.Compare(duration.Duration{}) > 0) { - convErr = errors.Errorf("interval value %v too large, AS OF interval must be <= -%v", d, time.Microsecond) - } else if (usage == Split && d.Duration.Compare(duration.Duration{}) < 0) { - convErr = errors.Errorf("interval value %v too small, SPLIT interval must be >= %v", d, time.Microsecond) - } ts.WallTime = duration.Add(stmtTimestamp, d.Duration).UnixNano() default: convErr = errors.WithSafeDetails( diff --git a/pkg/sql/sem/asof/type_check.go b/pkg/sql/sem/asof/type_check.go index 738729d6fac1..704a91fb0c4b 100644 --- a/pkg/sql/sem/asof/type_check.go +++ b/pkg/sql/sem/asof/type_check.go @@ -55,7 +55,6 @@ func EvalSystemTimeExpr( semaCtx *tree.SemaContext, systemTimeExpr tree.Expr, op string, - usage DatumToHLCUsage, ) (hlc.Timestamp, error) { typedExpr, err := TypeCheckSystemTimeExpr(ctx, semaCtx, systemTimeExpr, op) if err != nil { @@ -69,5 +68,5 @@ func EvalSystemTimeExpr( return hlc.MaxTimestamp, nil } stmtTimestamp := evalCtx.GetStmtTimestamp() - return DatumToHLC(evalCtx, stmtTimestamp, d, usage) + return DatumToHLC(evalCtx, stmtTimestamp, d) } diff --git a/pkg/sql/show_fingerprints.go b/pkg/sql/show_fingerprints.go index e4abdd700587..962e97d1785c 100644 --- a/pkg/sql/show_fingerprints.go +++ b/pkg/sql/show_fingerprints.go @@ -106,7 +106,7 @@ func evalShowTenantFingerprintOptions( ) (*resolvedShowTenantFingerprintOptions, error) { r := &resolvedShowTenantFingerprintOptions{} if options.StartTimestamp != nil { - ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.StartTimestamp, op, asof.ShowTenantFingerprint) + ts, err := asof.EvalSystemTimeExpr(ctx, evalCtx, semaCtx, options.StartTimestamp, op) if err != nil { return nil, err } diff --git a/pkg/sql/split.go b/pkg/sql/split.go index d98211a2e1f9..e4ba24478e13 100644 --- a/pkg/sql/split.go +++ b/pkg/sql/split.go @@ -124,7 +124,7 @@ func parseExpirationTime( return hlc.MaxTimestamp, nil } stmtTimestamp := evalCtx.GetStmtTimestamp() - ts, err := asof.DatumToHLC(evalCtx, stmtTimestamp, d, asof.Split) + ts, err := asof.DatumToHLC(evalCtx, stmtTimestamp, d) if err != nil { return ts, errors.Wrap(err, "SPLIT AT") } diff --git a/pkg/sql/split_test.go b/pkg/sql/split_test.go index 2172662ab284..c1b38f741c33 100644 --- a/pkg/sql/split_test.go +++ b/pkg/sql/split_test.go @@ -145,7 +145,7 @@ func TestSplitAt(t *testing.T) { }, { in: "ALTER TABLE d.i SPLIT AT VALUES (17) WITH EXPIRATION '-1 day'::interval", - error: "SPLIT AT: interval value '-1 days' too small, SPLIT interval must be >= 1µs", + error: "SPLIT AT: expiration time should be greater than or equal to current time", }, { in: "ALTER TABLE d.i SPLIT AT VALUES (17) WITH EXPIRATION '0.1us'",