From b122d9d40af9caf2f411f3fb042b0c556dafd8f4 Mon Sep 17 00:00:00 2001 From: Drew Kimball Date: Tue, 3 Oct 2023 18:03:44 -0600 Subject: [PATCH] sql: fix nil-pointer error in local retry after an error. However, the retry logic unconditionally updated a field of `DistSQLReceiver` that may be nil, which could cause a nil-pointer error in some code paths (e.g. apply-join). This patch adds a check that the field is non-nil, as is done for other places where it is updated. There is no release note because the change has not yet made it into a release. Fixes #105451 Release note: None --- pkg/sql/distsql_running.go | 4 +- .../logictest/testdata/logic_test/apply_join | 70 +++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/pkg/sql/distsql_running.go b/pkg/sql/distsql_running.go index 12169e3f6967..cfb2e94d20ab 100644 --- a/pkg/sql/distsql_running.go +++ b/pkg/sql/distsql_running.go @@ -1242,7 +1242,9 @@ func (r *DistSQLReceiver) resetForLocalRerun(stats topLevelQueryStats) { r.closed = false r.stats = stats r.egressCounter = nil - atomic.StoreUint64(r.progressAtomic, math.Float64bits(0)) + if r.progressAtomic != nil { + atomic.StoreUint64(r.progressAtomic, math.Float64bits(0)) + } } // Release releases this DistSQLReceiver back to the pool. diff --git a/pkg/sql/logictest/testdata/logic_test/apply_join b/pkg/sql/logictest/testdata/logic_test/apply_join index 8f196f12980e..82355d725f03 100644 --- a/pkg/sql/logictest/testdata/logic_test/apply_join +++ b/pkg/sql/logictest/testdata/logic_test/apply_join @@ -665,3 +665,73 @@ CREATE MATERIALIZED VIEW v1 AS UNION SELECT aid, pid FROM cte2 ); + +# Regression test for #111327 - the query shouldn't cause a nil-pointer error. +statement ok +CREATE TYPE greeting AS ENUM ('hello', 'howdy', 'hi', 'good day', 'morning'); + +statement ok +CREATE TABLE IF NOT EXISTS seed AS +SELECT + g :: INT2 AS _int2, + g :: INT4 AS _int4, + g :: INT8 AS _int8, + g :: FLOAT4 AS _float4, + g :: FLOAT8 AS _float8, + '2001-01-01' :: DATE + g AS _date, + '2001-01-01' :: TIMESTAMP + g * '1 day'::INTERVAL AS _timestamp, + '2001-01-01' :: TIMESTAMPTZ + g * '1 day'::INTERVAL AS _timestamptz, + g * '1 day' :: INTERVAL AS _interval, + g % 2 = 1 AS _bool, + g :: DECIMAL AS _decimal, + g :: STRING AS _string, + g :: STRING :: BYTES AS _bytes, + substring('00000000-0000-0000-0000-' || g :: STRING || '00000000000', 1, 36):: UUID AS _uuid, + '0.0.0.0' :: INET + g AS _inet, + g :: STRING :: JSONB AS _jsonb, + enum_range('hello' :: greeting) [g] as _enum +FROM + generate_series(1, 5) AS g; + +statement ok +INSERT INTO seed DEFAULT VALUES; + +statement ok +CREATE INDEX on seed (_int8, _float8, _date); + +statement ok +CREATE INVERTED INDEX on seed (_jsonb); + +statement error pgcode 22P02 pq: pg_lsn\(\): invalid input syntax for type pg_lsn: \"1\" +SELECT + tab378984.crdb_internal_mvcc_timestamp AS "%pcol857759", + '48 years 7 mons 894 days 13:39:26.674765':::INTERVAL AS col857760, + tab378983.tableoid AS "coL857761", + tab378983.crdb_internal_mvcc_timestamp AS col857762, + (SELECT (-4999644074744333745):::INT8 AS "co""l857763" LIMIT 1:::INT8) AS col857764, + tab378983._inet AS col857765, + '2011-06-28 16:37:44.000635+00':::TIMESTAMPTZ AS col857766, + tab378984._bool AS col857767, + tab378983.tableoid AS col857768, + tab378984._timestamptz AS col857769, + NULL AS "Co😽l857770", + tab378984._string AS "c)ol857771", + NULL AS col857772, + tab378983._int4 AS c🙃ol857773, + tab378984._interval AS " col857774", + tab378984.crdb_internal_mvcc_timestamp AS "c%69ol'857775" +FROM + seed@seed__int8__float8__date_idx AS tab378983, + seed@[0] AS tab378984 +WHERE + ( + true + AND ( + '9E82DF40/BC8A8379':::PG_LSN::PG_LSN NOT IN ( + SELECT pg_lsn(tab378984._string::STRING)::PG_LSN::PG_LSN AS col857758 + FROM seed@[0] AS "%ptAb%v378985" WHERE "%ptAb%v378985"._bool LIMIT 22:::INT8 + ) + ) + ) +ORDER BY tab378983._timestamptz ASC NULLS FIRST +LIMIT 78:::INT8;