From 88a5adc6ec57d6205ec6946ab007cfd79598e95a Mon Sep 17 00:00:00 2001 From: Sean Chittenden Date: Fri, 21 Jul 2023 13:02:28 -0700 Subject: [PATCH 1/5] go.mod: upgrade pgx v4 to 4.18.1 d15cc95a Add fix for using a context with a value in BeforeConnect 3edc1b5b Fix query sanitizer dfce986b Fix panic when logging batch error 72fe5949 Upgrade to puddle v1.3.0 bce26b85 Fix atomic alignment on 32-bit platforms 1d748d9b Failsafe timeout for background pool connections 7ce634d6 Ensure there is a timeout for background pool connections 91c9e841 Ignore cancellation in puddle constructor a814153a pgxpool: health check should avoid going below minConns Release note: None --- DEPS.bzl | 30 +++++++++++++++--------------- build/bazelutil/distdir_files.bzl | 10 +++++----- go.mod | 10 +++++----- go.sum | 27 +++++++++++++++------------ 4 files changed, 40 insertions(+), 37 deletions(-) diff --git a/DEPS.bzl b/DEPS.bzl index 5444dcd01d5d..8a6af6f3644a 100644 --- a/DEPS.bzl +++ b/DEPS.bzl @@ -4809,10 +4809,10 @@ def go_deps(): name = "com_github_jackc_pgconn", build_file_proto_mode = "disable_global", importpath = "github.com/jackc/pgconn", - sha256 = "4d9bf1309f5cdbd589d60a485fb5d5d7333edf9652c2dd47b7dd31b12dda887e", - strip_prefix = "github.com/jackc/pgconn@v1.13.1-0.20221001150415-49cbf4659151", + sha256 = "d7935c04e5ee85f2dcab090692d2c24008071865a3af3581580bcc331a8f41d5", + strip_prefix = "github.com/jackc/pgconn@v1.14.0", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.13.1-0.20221001150415-49cbf4659151.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.14.0.zip", ], ) go_repository( @@ -4859,10 +4859,10 @@ def go_deps(): name = "com_github_jackc_pgproto3_v2", build_file_proto_mode = "disable_global", importpath = "github.com/jackc/pgproto3/v2", - sha256 = "57884e299825af31fd01268659f1e671883b73b708a51230da14d6f8ee0e4e36", - strip_prefix = "github.com/jackc/pgproto3/v2@v2.3.1", + sha256 = "e6bafa5c3522534557a818f56939dde7b496c6669a5db9a74a0c91ab5290612c", + strip_prefix = "github.com/jackc/pgproto3/v2@v2.3.2", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.1.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.2.zip", ], ) go_repository( @@ -4879,20 +4879,20 @@ def go_deps(): name = "com_github_jackc_pgtype", build_file_proto_mode = "disable_global", importpath = "github.com/jackc/pgtype", - sha256 = "6a257b81c0bd386d6241219a14ebd41d574a02aeaeb3942670c06441b864dcad", - strip_prefix = "github.com/jackc/pgtype@v1.11.0", + sha256 = "7e67f5b944cbd401025c6473e624ef61ed196e3ed0f77ed437b0621cf820c0c9", + strip_prefix = "github.com/jackc/pgtype@v1.14.0", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.11.0.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.14.0.zip", ], ) go_repository( name = "com_github_jackc_pgx_v4", build_file_proto_mode = "disable_global", importpath = "github.com/jackc/pgx/v4", - sha256 = "c3a169a68ff0e56f9f81eee4de4d2fd2a5ec7f4d6be159159325f4863c80bd10", - strip_prefix = "github.com/jackc/pgx/v4@v4.16.1", + sha256 = "5ca92c5bf58979d9e978f6b849e02eb319d2587565375fe875a29d10d84cfadc", + strip_prefix = "github.com/jackc/pgx/v4@v4.18.1", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v4/com_github_jackc_pgx_v4-v4.16.1.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v4/com_github_jackc_pgx_v4-v4.18.1.zip", ], ) go_repository( @@ -4909,10 +4909,10 @@ def go_deps(): name = "com_github_jackc_puddle", build_file_proto_mode = "disable_global", importpath = "github.com/jackc/puddle", - sha256 = "40d73550686666eb1f6df02b65008b2a4c98cfed1254dc4866e6ebe95fbc5c95", - strip_prefix = "github.com/jackc/puddle@v1.2.1", + sha256 = "b1eb42bb3cf9a430146af79cb183860b9dddfca51844c2d4b447dc2f43becc55", + strip_prefix = "github.com/jackc/puddle@v1.3.0", urls = [ - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/com_github_jackc_puddle-v1.2.1.zip", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/com_github_jackc_puddle-v1.3.0.zip", ], ) go_repository( diff --git a/build/bazelutil/distdir_files.bzl b/build/bazelutil/distdir_files.bzl index f42a5c8b6e5d..ef35852255da 100644 --- a/build/bazelutil/distdir_files.bzl +++ b/build/bazelutil/distdir_files.bzl @@ -636,17 +636,17 @@ DISTDIR_FILES = { "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/j-keck/arping/com_github_j_keck_arping-v0.0.0-20160618110441-2cf9dc699c56.zip": "6001c94a8c4eed55718f627346cb685cce67369ca5c29ae059f58f7abd8bd8a7", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/chunkreader/com_github_jackc_chunkreader-v1.0.0.zip": "e204c917e2652ffe047f5c8b031192757321f568654e3df8408bf04178df1408", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/chunkreader/v2/com_github_jackc_chunkreader_v2-v2.0.1.zip": "6e3f4b7d9647f31061f6446ae10de71fc1407e64f84cd0949afac0cd231e8dd2", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.13.1-0.20221001150415-49cbf4659151.zip": "4d9bf1309f5cdbd589d60a485fb5d5d7333edf9652c2dd47b7dd31b12dda887e", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgconn/com_github_jackc_pgconn-v1.14.0.zip": "d7935c04e5ee85f2dcab090692d2c24008071865a3af3581580bcc331a8f41d5", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgio/com_github_jackc_pgio-v1.0.0.zip": "1a83c03d53f6a40339364cafcbbabb44238203c79ca0c9b98bf582d0df0e0468", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgmock/com_github_jackc_pgmock-v0.0.0-20210724152146-4ad1a8207f65.zip": "0fffd0a7a67dbdfafa04297e51028c6d2d08cd6691f3b6d78d7ae6502d3d4cf2", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgpassfile/com_github_jackc_pgpassfile-v1.0.0.zip": "1cc79fb0b80f54b568afd3f4648dd1c349f746ad7c379df8d7f9e0eb1cac938b", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/com_github_jackc_pgproto3-v1.1.0.zip": "e3766bee50ed74e49a067b2c4797a2c69015cf104bf3f3624cd483a9e940b4ee", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.1.zip": "57884e299825af31fd01268659f1e671883b73b708a51230da14d6f8ee0e4e36", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgproto3/v2/com_github_jackc_pgproto3_v2-v2.3.2.zip": "e6bafa5c3522534557a818f56939dde7b496c6669a5db9a74a0c91ab5290612c", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgservicefile/com_github_jackc_pgservicefile-v0.0.0-20221227161230-091c0ba34f0a.zip": "1f8bdf75b2a0d750e56c2a94b1d1b0b5be4b29d6df056aebd997162c29bfd8ab", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.11.0.zip": "6a257b81c0bd386d6241219a14ebd41d574a02aeaeb3942670c06441b864dcad", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v4/com_github_jackc_pgx_v4-v4.16.1.zip": "c3a169a68ff0e56f9f81eee4de4d2fd2a5ec7f4d6be159159325f4863c80bd10", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgtype/com_github_jackc_pgtype-v1.14.0.zip": "7e67f5b944cbd401025c6473e624ef61ed196e3ed0f77ed437b0621cf820c0c9", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v4/com_github_jackc_pgx_v4-v4.18.1.zip": "5ca92c5bf58979d9e978f6b849e02eb319d2587565375fe875a29d10d84cfadc", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/pgx/v5/com_github_jackc_pgx_v5-v5.4.2.zip": "198eebac7e875b51616090fe2e3694e6f27e335afcc3c47ae9991497ade7f52a", - "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/com_github_jackc_puddle-v1.2.1.zip": "40d73550686666eb1f6df02b65008b2a4c98cfed1254dc4866e6ebe95fbc5c95", + "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/com_github_jackc_puddle-v1.3.0.zip": "b1eb42bb3cf9a430146af79cb183860b9dddfca51844c2d4b447dc2f43becc55", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jackc/puddle/v2/com_github_jackc_puddle_v2-v2.2.0.zip": "b99ea95df0c0298caf2be786c9eba511bfde2046eccfaa06e89b3e460ab406b0", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jaegertracing/jaeger/com_github_jaegertracing_jaeger-v1.18.1.zip": "256a95b2a52a66494aca6d354224bb450ff38ce3ea1890af46a7c8dc39203891", "https://storage.googleapis.com/cockroach-godeps/gomod/github.com/jcmturner/aescts/v2/com_github_jcmturner_aescts_v2-v2.0.0.zip": "717a211ad4aac248cf33cadde73059c13f8e9462123a0ab2fed5c5e61f7739d7", diff --git a/go.mod b/go.mod index 01950c50e2ed..f49da999bab8 100644 --- a/go.mod +++ b/go.mod @@ -67,14 +67,14 @@ require ( // the SQL team. require ( github.com/jackc/chunkreader/v2 v2.0.1 // indirect - github.com/jackc/pgconn v1.13.1-0.20221001150415-49cbf4659151 + github.com/jackc/pgconn v1.14.0 github.com/jackc/pgio v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgproto3/v2 v2.3.1 + github.com/jackc/pgproto3/v2 v2.3.2 github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect - github.com/jackc/pgtype v1.11.0 - github.com/jackc/pgx/v4 v4.16.1 - github.com/jackc/puddle v1.2.1 // indirect + github.com/jackc/pgtype v1.14.0 + github.com/jackc/pgx/v4 v4.18.1 + github.com/jackc/puddle v1.3.0 // indirect ) require ( diff --git a/go.sum b/go.sum index d632df26d70e..943a61d2f58e 100644 --- a/go.sum +++ b/go.sum @@ -1368,9 +1368,8 @@ github.com/jackc/pgconn v0.0.0-20190831204454-2fabfa3c18b7/go.mod h1:ZJKsE/KZfsU github.com/jackc/pgconn v1.8.0/go.mod h1:1C2Pb36bGIP9QHGBYCjnyhqu7Rv3sGshaQUvmfGIB/o= github.com/jackc/pgconn v1.9.0/go.mod h1:YctiPyvzfU11JFxoXokUOOKQXQmDMoJL9vJzHH8/2JY= github.com/jackc/pgconn v1.9.1-0.20210724152538-d89c8390a530/go.mod h1:4z2w8XhRbP1hYxkpTuBjTS3ne3J48K83+u0zoyvg2pI= -github.com/jackc/pgconn v1.12.1/go.mod h1:ZkhRC59Llhrq3oSfrikvwQ5NaxYExr6twkdkMLaKono= -github.com/jackc/pgconn v1.13.1-0.20221001150415-49cbf4659151 h1:bPKk32KlGLQ/SWtOc3onTzZ/km0BIiwwYBqt+8YlKwU= -github.com/jackc/pgconn v1.13.1-0.20221001150415-49cbf4659151/go.mod h1:AnowpAqO4CMIIJNZl2VJp+KrkAZciAkhEl0W0JIobpI= +github.com/jackc/pgconn v1.14.0 h1:vrbA9Ud87g6JdFWkHTJXppVce58qPIdP7N8y0Ml/A7Q= +github.com/jackc/pgconn v1.14.0/go.mod h1:9mBNlny0UvkgJdCDvdVHYSjI+8tD2rnKK69Wz8ti++E= github.com/jackc/pgio v1.0.0 h1:g12B9UwVnzGhueNavwioyEEpAmqMe1E/BN9ES+8ovkE= github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bYf8= github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= @@ -1386,9 +1385,8 @@ github.com/jackc/pgproto3/v2 v2.0.0-rc3/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvW github.com/jackc/pgproto3/v2 v2.0.0-rc3.0.20190831210041-4c03ce451f29/go.mod h1:ryONWYqW6dqSg1Lw6vXNMXoBJhpzvWKnT95C46ckYeM= github.com/jackc/pgproto3/v2 v2.0.6/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgproto3/v2 v2.3.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= -github.com/jackc/pgproto3/v2 v2.3.1 h1:nwj7qwf0S+Q7ISFfBndqeLwSwxs+4DPsbRFjECT1Y4Y= -github.com/jackc/pgproto3/v2 v2.3.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= +github.com/jackc/pgproto3/v2 v2.3.2 h1:7eY55bdBeCz1F2fTzSz69QC+pG46jYq9/jtSPiJ5nn0= +github.com/jackc/pgproto3/v2 v2.3.2/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= @@ -1396,21 +1394,21 @@ github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01C github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= github.com/jackc/pgtype v1.8.1-0.20210724151600-32e20a603178/go.mod h1:C516IlIV9NKqfsMCXTdChteoXmwgUceqaLfjg2e3NlM= -github.com/jackc/pgtype v1.11.0 h1:u4uiGPz/1hryuXzyaBhSk6dnIyyG2683olG2OV+UUgs= -github.com/jackc/pgtype v1.11.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= +github.com/jackc/pgtype v1.14.0 h1:y+xUdabmyMkJLyApYuPj38mW+aAIqCe5uuBB51rH3Vw= +github.com/jackc/pgtype v1.14.0/go.mod h1:LUMuVrfsFfdKGLw+AFFVv6KtHOFMwRgDDzBt76IqCA4= github.com/jackc/pgx/v4 v4.0.0-20190420224344-cc3461e65d96/go.mod h1:mdxmSJJuR08CZQyj1PVQBHy9XOp5p8/SHH6a0psbY9Y= github.com/jackc/pgx/v4 v4.0.0-20190421002000-1b8f0016e912/go.mod h1:no/Y67Jkk/9WuGR0JG/JseM9irFbnEPbuWV2EELPNuM= github.com/jackc/pgx/v4 v4.0.0-pre1.0.20190824185557-6972a5742186/go.mod h1:X+GQnOEnf1dqHGpw7JmHqHc1NxDoalibchSk9/RWuDc= github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= -github.com/jackc/pgx/v4 v4.16.1 h1:JzTglcal01DrghUqt+PmzWsZx/Yh7SC/CTQmSBMTd0Y= -github.com/jackc/pgx/v4 v4.16.1/go.mod h1:SIhx0D5hoADaiXZVyv+3gSm3LCIIINTVO0PficsvWGQ= +github.com/jackc/pgx/v4 v4.18.1 h1:YP7G1KABtKpB5IHrO9vYwSrCOhs7p3uqhvhhQBptya0= +github.com/jackc/pgx/v4 v4.18.1/go.mod h1:FydWkUyadDmdNH/mHnGob881GawxeEm7TcMCzkb+qQE= github.com/jackc/pgx/v5 v5.4.2 h1:u1gmGDwbdRUZiwisBm/Ky2M14uQyUP65bG8+20nnyrg= github.com/jackc/pgx/v5 v5.4.2/go.mod h1:q6iHT8uDNXWiFNOlRqJzBTaSH3+2xCXkokxHZC5qWFY= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= -github.com/jackc/puddle v1.2.1 h1:gI8os0wpRXFd4FiAY2dWiqRK037tjj3t7rKFeO4X5iw= -github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0= +github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle/v2 v2.2.0 h1:RdcDk92EJBuBS55nQMMYFXTxwstHug4jkhT5pq8VxPk= github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jaegertracing/jaeger v1.18.1 h1:eFqjEpTKq2FfiZ/YX53oxeCePdIZyWvDfXaTAGj0r5E= @@ -2449,6 +2447,7 @@ golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220210151621-f4118a5b28e2/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220427172511-eb4f295cb31f/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= +golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= golang.org/x/crypto v0.9.0 h1:LF6fAI+IutBocDJ2OT0Q1g8plpYljMZ4+lty+dsqw3g= golang.org/x/crypto v0.9.0/go.mod h1:yrmDGqONDYtNj3tH8X9dzUun2m2lzPa9ngI6/RUPGR0= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -2585,6 +2584,7 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.0.0-20220725212005-46097bf591d3/go.mod h1:AaygXjzTFtRAg2ttMY5RMuhpJ3cNnI0XpyFJD1iQRSM= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= golang.org/x/oauth2 v0.0.0-20170207211851-4464e7848382/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -2766,6 +2766,7 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= @@ -2773,6 +2774,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= golang.org/x/term v0.8.0 h1:n5xxQn2i3PC0yLAbjTpNT85q/Kgzcr2gIoX9OrJUols= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -2786,6 +2788,7 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= From 3744aceeb63ba20d6241933b3c3c68a339361709 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 7 Aug 2023 14:51:51 +0000 Subject: [PATCH 2/5] backupccl: make SHOW BACKUP timestamps timestampTZ Release note (sql change): SHOW BACKUP's timestamp columns are now TIMESTAMPTZ, meaning they render in the session offset. Epic: CRDB-24406. --- pkg/ccl/backupccl/show.go | 8 +++---- pkg/ccl/backupccl/show_test.go | 14 ++++++------ .../testdata/backup-restore/show_backup | 22 +++++++++++++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/pkg/ccl/backupccl/show.go b/pkg/ccl/backupccl/show.go index e1f7731fea42..8060350a3aef 100644 --- a/pkg/ccl/backupccl/show.go +++ b/pkg/ccl/backupccl/show.go @@ -732,8 +732,8 @@ func backupShowerHeaders(showSchemas bool, opts tree.ShowBackupOptions) colinfo. {Name: "object_name", Typ: types.String}, {Name: "object_type", Typ: types.String}, {Name: "backup_type", Typ: types.String}, - {Name: "start_time", Typ: types.Timestamp}, - {Name: "end_time", Typ: types.Timestamp}, + {Name: "start_time", Typ: types.TimestampTZ}, + {Name: "end_time", Typ: types.TimestampTZ}, {Name: "size_bytes", Typ: types.Int}, {Name: "rows", Typ: types.Int}, {Name: "is_full_cluster", Typ: types.Bool}, @@ -844,12 +844,12 @@ func backupShowerDefault( backupType = tree.NewDString("incremental") } start := tree.DNull - end, err := tree.MakeDTimestamp(timeutil.Unix(0, manifest.EndTime.WallTime), time.Nanosecond) + end, err := tree.MakeDTimestampTZ(timeutil.Unix(0, manifest.EndTime.WallTime), time.Nanosecond) if err != nil { return nil, err } if manifest.StartTime.WallTime != 0 { - start, err = tree.MakeDTimestamp(timeutil.Unix(0, manifest.StartTime.WallTime), time.Nanosecond) + start, err = tree.MakeDTimestampTZ(timeutil.Unix(0, manifest.StartTime.WallTime), time.Nanosecond) if err != nil { return nil, err } diff --git a/pkg/ccl/backupccl/show_test.go b/pkg/ccl/backupccl/show_test.go index dafc2c11f8e3..d1ef4d68b0f6 100644 --- a/pkg/ccl/backupccl/show_test.go +++ b/pkg/ccl/backupccl/show_test.go @@ -62,7 +62,7 @@ CREATE TABLE data.sc.t2 (a data.welcome); const full, inc, inc2 = localFoo + "/full", localFoo + "/inc", localFoo + "/inc2" - beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0] + beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0] sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, beforeTS), full) res := sqlDB.QueryStr(t, ` @@ -93,7 +93,7 @@ ORDER BY object_type, object_name`, full) // Backup the changes by appending to the base and by making a separate // inc backup. - incTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0] + incTS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0] sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, incTS), full) sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s' INCREMENTAL FROM $2`, incTS), inc, full) @@ -124,9 +124,9 @@ ORDER BY object_type, object_name`, full) // Truncate decimal places so Go's very rigid parsing will work. // TODO(bardin): Consider using a third-party library for this, or some kind // of time-freezing on the test cluster. - truncateBackupTimeRE := regexp.MustCompile(`^(.*\.[0-9]{2})[0-9]*$`) + truncateBackupTimeRE := regexp.MustCompile(`^(.*\.[0-9]{2})[0-9]*\+00$`) matchResult := truncateBackupTimeRE.FindStringSubmatch(beforeTS) - require.NotNil(t, matchResult) + require.NotNil(t, matchResult, "%s does not match %s", beforeTS, truncateBackupTimeRE) backupTime, err := time.Parse("2006-01-02 15:04:05.00", matchResult[1]) require.NoError(t, err) backupFolder := backupTime.Format(backupbase.DateBasedIntoFolderName) @@ -168,7 +168,7 @@ ORDER BY object_type, object_name`, full) // Backup the changes again, by appending to the base and by making a // separate inc backup. - inc2TS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0] + inc2TS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0] sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, inc2TS), full) sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s' INCREMENTAL FROM $2, $3`, inc2TS), inc2, full, inc) @@ -633,7 +633,7 @@ func TestShowBackupTenants(t *testing.T) { defer conn10.Close() tenant10 := sqlutils.MakeSQLRunner(conn10) tenant10.Exec(t, `CREATE DATABASE foo; CREATE TABLE foo.bar(i int primary key); INSERT INTO foo.bar VALUES (110), (210)`) - beforeTS := systemDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0] + beforeTS := systemDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0] systemDB.Exec(t, fmt.Sprintf(`BACKUP TENANT 10 TO 'nodelocal://1/t10' AS OF SYSTEM TIME '%s'`, beforeTS)) @@ -726,7 +726,7 @@ func TestShowBackupWithDebugIDs(t *testing.T) { const full = localFoo + "/full" - beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamp::string`)[0][0] + beforeTS := sqlDB.QueryStr(t, `SELECT now()::timestamptz::string`)[0][0] sqlDB.Exec(t, fmt.Sprintf(`BACKUP DATABASE data TO $1 AS OF SYSTEM TIME '%s'`, beforeTS), full) // extract the object IDs for the database and public schema diff --git a/pkg/ccl/backupccl/testdata/backup-restore/show_backup b/pkg/ccl/backupccl/testdata/backup-restore/show_backup index bbd665302e92..5811ee1f095a 100644 --- a/pkg/ccl/backupccl/testdata/backup-restore/show_backup +++ b/pkg/ccl/backupccl/testdata/backup-restore/show_backup @@ -26,6 +26,28 @@ SELECT sum(size_bytes) FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/' WITH s ---- 0 +query-sql +SET TIME ZONE 'UTC'; +---- + +query-sql +SELECT end_time, end_time AT TIME ZONE 'MST' FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/' WITH skip size] limit 1; +---- +2022-08-03 16:00:28.984252 +0000 UTC 2022-08-03 09:00:28.984252 +0000 +0000 + +query-sql +SET TIME ZONE 'MST'; +---- + +query-sql +SELECT end_time, end_time AT TIME ZONE 'MST' FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/' WITH skip size] limit 1; +---- +2022-08-03 09:00:28.984252 -0700 MST 2022-08-03 09:00:28.984252 +0000 +0000 + +query-sql +SET TIME ZONE 'UTC'; +---- + # This backup is completely valid, but has no jobs. query-sql regex=No\sproblems\sfound! SELECT * FROM [SHOW BACKUP VALIDATE FROM 'valid-22.2' IN 'nodelocal://1/']; From 20c43ab5a5aaa06948490de9f86e353b110e7de8 Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Thu, 27 Jul 2023 16:50:45 -0700 Subject: [PATCH 3/5] sql: prevent panic when using UDF as EXECUTE argument Fixes #99008 Release note (bug fix): A bug has been fixed that caused nodes to crash when attempting to `EXECUTE` a prepared statement with an argument that referenced a user-defined function. This bug was present since user-defined functions were introduced in version 22.2. --- pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go | 7 +++++++ pkg/sql/execute.go | 3 +-- pkg/sql/logictest/testdata/logic_test/udf_prepare | 8 ++++++++ pkg/sql/logictest/tests/fakedist-disk/generated_test.go | 7 +++++++ .../logictest/tests/fakedist-vec-off/generated_test.go | 7 +++++++ pkg/sql/logictest/tests/fakedist/generated_test.go | 7 +++++++ .../tests/local-legacy-schema-changer/generated_test.go | 7 +++++++ .../tests/local-mixed-22.2-23.1/generated_test.go | 7 +++++++ pkg/sql/logictest/tests/local-vec-off/generated_test.go | 7 +++++++ pkg/sql/logictest/tests/local/generated_test.go | 7 +++++++ pkg/sql/sem/eval/expr.go | 4 ++++ 11 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 pkg/sql/logictest/testdata/logic_test/udf_prepare diff --git a/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go b/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go index 686f4ee77fd0..c9f7ca965bc2 100644 --- a/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go +++ b/pkg/ccl/logictestccl/tests/3node-tenant/generated_test.go @@ -2208,6 +2208,13 @@ func TestTenantLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestTenantLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestTenantLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/execute.go b/pkg/sql/execute.go index d3f3fca1acfa..30cbda423374 100644 --- a/pkg/sql/execute.go +++ b/pkg/sql/execute.go @@ -35,7 +35,6 @@ func (p *planner) fillInPlaceholders( } qArgs := make(tree.QueryArguments, len(params)) - var semaCtx tree.SemaContext for i, e := range params { idx := tree.PlaceholderIdx(i) @@ -54,7 +53,7 @@ func (p *planner) fillInPlaceholders( } } typedExpr, err := schemaexpr.SanitizeVarFreeExpr( - ctx, e, typ, "EXECUTE parameter" /* context */, &semaCtx, volatility.Volatile, true, /*allowAssignmentCast*/ + ctx, e, typ, "EXECUTE parameter" /* context */, p.SemaCtx(), volatility.Volatile, true, /*allowAssignmentCast*/ ) if err != nil { return nil, pgerror.WithCandidateCode(err, pgcode.WrongObjectType) diff --git a/pkg/sql/logictest/testdata/logic_test/udf_prepare b/pkg/sql/logictest/testdata/logic_test/udf_prepare new file mode 100644 index 000000000000..ccaa79123d75 --- /dev/null +++ b/pkg/sql/logictest/testdata/logic_test/udf_prepare @@ -0,0 +1,8 @@ +statement ok +CREATE FUNCTION f() RETURNS INT LANGUAGE SQL AS $$ SELECT 1 $$ + +statement ok +PREPARE p AS SELECT $1::INT + +statement error pgcode 0A000 cannot evaluate function in this context +EXECUTE p(f()) diff --git a/pkg/sql/logictest/tests/fakedist-disk/generated_test.go b/pkg/sql/logictest/tests/fakedist-disk/generated_test.go index eb690aaa54bb..ec09ecdc7fc2 100644 --- a/pkg/sql/logictest/tests/fakedist-disk/generated_test.go +++ b/pkg/sql/logictest/tests/fakedist-disk/generated_test.go @@ -2172,6 +2172,13 @@ func TestLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go b/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go index 617a91b7a2cb..8e6b1dce4ca9 100644 --- a/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go +++ b/pkg/sql/logictest/tests/fakedist-vec-off/generated_test.go @@ -2179,6 +2179,13 @@ func TestLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/fakedist/generated_test.go b/pkg/sql/logictest/tests/fakedist/generated_test.go index 0f3f3ee01a80..46de667d0de3 100644 --- a/pkg/sql/logictest/tests/fakedist/generated_test.go +++ b/pkg/sql/logictest/tests/fakedist/generated_test.go @@ -2193,6 +2193,13 @@ func TestLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/local-legacy-schema-changer/generated_test.go b/pkg/sql/logictest/tests/local-legacy-schema-changer/generated_test.go index 757a834a42dc..9629f5d5f9e9 100644 --- a/pkg/sql/logictest/tests/local-legacy-schema-changer/generated_test.go +++ b/pkg/sql/logictest/tests/local-legacy-schema-changer/generated_test.go @@ -2172,6 +2172,13 @@ func TestLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/local-mixed-22.2-23.1/generated_test.go b/pkg/sql/logictest/tests/local-mixed-22.2-23.1/generated_test.go index 744cce7f460b..f0a364df427f 100644 --- a/pkg/sql/logictest/tests/local-mixed-22.2-23.1/generated_test.go +++ b/pkg/sql/logictest/tests/local-mixed-22.2-23.1/generated_test.go @@ -2109,6 +2109,13 @@ func TestLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/local-vec-off/generated_test.go b/pkg/sql/logictest/tests/local-vec-off/generated_test.go index 196435026dde..1239431382e6 100644 --- a/pkg/sql/logictest/tests/local-vec-off/generated_test.go +++ b/pkg/sql/logictest/tests/local-vec-off/generated_test.go @@ -2200,6 +2200,13 @@ func TestLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/logictest/tests/local/generated_test.go b/pkg/sql/logictest/tests/local/generated_test.go index e330504a1aa4..df4ed432d094 100644 --- a/pkg/sql/logictest/tests/local/generated_test.go +++ b/pkg/sql/logictest/tests/local/generated_test.go @@ -2396,6 +2396,13 @@ func TestLogic_udf_plpgsql( runLogicTest(t, "udf_plpgsql") } +func TestLogic_udf_prepare( + t *testing.T, +) { + defer leaktest.AfterTest(t)() + runLogicTest(t, "udf_prepare") +} + func TestLogic_udf_privileges( t *testing.T, ) { diff --git a/pkg/sql/sem/eval/expr.go b/pkg/sql/sem/eval/expr.go index 497dd6636a91..65df7098d8e8 100644 --- a/pkg/sql/sem/eval/expr.go +++ b/pkg/sql/sem/eval/expr.go @@ -476,6 +476,10 @@ func (e *evaluator) EvalFuncExpr(ctx context.Context, expr *tree.FuncExpr) (tree return tree.DNull, err } + if fn.Body != "" { + return nil, pgerror.Newf(pgcode.FeatureNotSupported, "cannot evaluate function in this context") + } + res, err := fn.Fn.(FnOverload)(ctx, e.ctx(), args) if err != nil { return nil, expr.MaybeWrapError(err) From aab7109c642d3eb0be2f33285944e42970ab3e34 Mon Sep 17 00:00:00 2001 From: Marcus Gartner Date: Mon, 7 Aug 2023 12:10:42 -0400 Subject: [PATCH 4/5] sql: fix UDF with VOID return type Functions with VOID returns types should be allowed to produce any number of columns of any type from their last statement. Prior to this commit, a calling UDF with a VOID return type would error if the last statement in the UDF did not produce a value of type VOID. This commit fixes this minor bug. Fixes #108297 Release note (bug fix): The last SQL statement in a user-defined function with a VOID return type can now produce any number of columns of any type. This bug was present since UDFs were introduced in version 22.2. --- .../testdata/logic_test/udf_regressions | 45 +++++++++++++++++++ pkg/sql/opt/optbuilder/scalar.go | 18 ++++++++ pkg/sql/opt/optbuilder/testdata/udf | 45 ++++++++++++++++++- 3 files changed, 106 insertions(+), 2 deletions(-) diff --git a/pkg/sql/logictest/testdata/logic_test/udf_regressions b/pkg/sql/logictest/testdata/logic_test/udf_regressions index 25bfcb0adc67..892c7154667e 100644 --- a/pkg/sql/logictest/testdata/logic_test/udf_regressions +++ b/pkg/sql/logictest/testdata/logic_test/udf_regressions @@ -580,3 +580,48 @@ statement error pgcode 22P02 invalid input value for enum e105259: "foo" SELECT f() subtest end + + +# Regression test for #108297. UDFs with VOID return types should succeed when +# the last statement returns columns of any type. +subtest regression_108297 + +statement ok +CREATE OR REPLACE FUNCTION f108297() RETURNS VOID LANGUAGE SQL AS 'SELECT 1' + +query T +SELECT f108297() +---- +NULL + +statement ok +CREATE OR REPLACE FUNCTION f108297() RETURNS VOID LANGUAGE SQL AS $$ + SELECT 1, 'foo', NULL +$$ + +query T +SELECT f108297() +---- +NULL + +statement ok +CREATE SEQUENCE s108297 + +statement ok +CREATE OR REPLACE FUNCTION f108297() RETURNS VOID LANGUAGE SQL AS $$ + SELECT nextval('s108297') +$$ + +query T +SELECT f108297() +---- +NULL + +# Invoking the UDF above should have increment s108297 to 1, so calling nextval +# again should yield 2. +query I +SELECT nextval('s108297') +---- +2 + +subtest end diff --git a/pkg/sql/opt/optbuilder/scalar.go b/pkg/sql/opt/optbuilder/scalar.go index 40ed863989d7..30dfe170a363 100644 --- a/pkg/sql/opt/optbuilder/scalar.go +++ b/pkg/sql/opt/optbuilder/scalar.go @@ -24,6 +24,7 @@ import ( "github.com/cockroachdb/cockroach/pkg/sql/opt/props" "github.com/cockroachdb/cockroach/pkg/sql/opt/props/physical" "github.com/cockroachdb/cockroach/pkg/sql/parser" + "github.com/cockroachdb/cockroach/pkg/sql/parser/statements" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode" "github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror" plpgsql "github.com/cockroachdb/cockroach/pkg/sql/plpgsql/parser" @@ -728,6 +729,21 @@ func (b *Builder) buildUDF( if err != nil { panic(err) } + // Add a VALUES (NULL) statement if the return type of the function is + // VOID. We cant simply project NULL from the last statement because all + // column would be pruned and the contents of last statement would not + // be executed. + // TODO(mgartner): This will add some planning overhead for every + // invocation of the function. Is there a more efficient way to do this? + if rtyp.Family() == types.VoidFamily { + stmts = append(stmts, statements.Statement[tree.Statement]{ + AST: &tree.Select{ + Select: &tree.ValuesClause{ + Rows: []tree.Exprs{{tree.DNull}}, + }, + }, + }) + } body = make([]memo.RelExpr, len(stmts)) bodyProps = make([]*physical.Required, len(stmts)) @@ -750,6 +766,8 @@ func (b *Builder) buildUDF( if err != nil { panic(err) } + // TODO(#108298): Figure out how to handle PLpgSQL functions with VOID + // return types. var plBuilder plpgsqlBuilder plBuilder.init(b, colRefs, o.Types.(tree.ParamTypes), stmt.AST, rtyp) stmtScope := plBuilder.build(stmt.AST, bodyScope) diff --git a/pkg/sql/opt/optbuilder/testdata/udf b/pkg/sql/opt/optbuilder/testdata/udf index e73a283147f0..3f9cb89abbff 100644 --- a/pkg/sql/opt/optbuilder/testdata/udf +++ b/pkg/sql/opt/optbuilder/testdata/udf @@ -1031,6 +1031,47 @@ project └── variable: s:2 +# -------------------------------------------------- +# UDFs with VOID return type. +# -------------------------------------------------- + +exec-ddl +CREATE FUNCTION retvoid(i INT) RETURNS VOID LANGUAGE SQL AS 'SELECT i' +---- + +build format=show-scalars +SELECT retvoid(1) +---- +project + ├── columns: retvoid:5 + ├── values + │ └── tuple + └── projections + └── udf: retvoid [as=retvoid:5] + ├── args + │ └── const: 1 + ├── params: i:1 + └── body + ├── project + │ ├── columns: i:2 + │ ├── values + │ │ └── tuple + │ └── projections + │ └── variable: i:1 [as=i:2] + └── project + ├── columns: column4:4 + ├── limit + │ ├── columns: column1:3 + │ ├── values + │ │ ├── columns: column1:3 + │ │ └── tuple + │ │ └── null + │ └── const: 1 + └── projections + └── assignment-cast: VOID [as=column4:4] + └── variable: column1:3 + + # -------------------------------------------------- # UDFs that are STRICT/RETURNS NULL ON NULL INPUT. # -------------------------------------------------- @@ -1699,11 +1740,11 @@ build set=enable_multiple_modifications_of_table=true SELECT upd_ups(1, 2, 3) ---- project - ├── columns: upd_ups:27 + ├── columns: upd_ups:29 ├── values │ └── () └── projections - └── upd_ups(1, 2, 3) [as=upd_ups:27] + └── upd_ups(1, 2, 3) [as=upd_ups:29] exec-ddl CREATE FUNCTION ups2(a1 INT, b1 INT, c1 INT, a2 INT, b2 INT, c2 INT) RETURNS BOOL LANGUAGE SQL AS $$ From 71e7a501f3898914658ddcdb07293dd91d92da80 Mon Sep 17 00:00:00 2001 From: Sean Barag Date: Mon, 7 Aug 2023 13:49:48 -0700 Subject: [PATCH 5/5] build: use typescript@5.1.6 via Bazel Commit f7a8aa2ec57 (ui: upgrade typescript from v4 to v5, 2023-08-03) recently upgraded to TypeScript 5.1.6. Keep the version used by rules_ts in-sync. Epic: none Release note: None --- WORKSPACE | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WORKSPACE b/WORKSPACE index 8d417304bd4c..001a112214a4 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -237,7 +237,9 @@ ts_http_archive( name = "npm_typescript", build_file = "@aspect_rules_ts//ts:BUILD.typescript", urls = ["https://storage.googleapis.com/cockroach-npm-deps/typescript/-/typescript-{}.tgz"], - version = "4.2.4", + version = "5.1.6", + # v5.1.6 isn't known to rules_ts 1.4.0 (nor to any published rules_ts version as-of 7 Aug 2023). + integrity = "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", ) # NOTE: The version is expected to match up to what version we use in db-console. # TODO(ricky): We should add a lint check to ensure it does match.