Skip to content

Commit

Permalink
Merge pull request #117556 from rharding6373/backport23.1-117318-117457
Browse files Browse the repository at this point in the history
release-23.1: sql: allow empty search path parameters
  • Loading branch information
rharding6373 authored Jan 11, 2024
2 parents cd1de07 + 80969fa commit aca59a6
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
4 changes: 1 addition & 3 deletions pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,7 @@ func newSessionData(args SessionArgs) *sessiondata.SessionData {
sd.CustomOptions[k] = v
}
}
sd.SearchPath = sessiondata.DefaultSearchPathForUser(sd.User())
populateMinimalSessionData(sd)
return sd
}
Expand All @@ -955,9 +956,6 @@ func populateMinimalSessionData(sd *sessiondata.SessionData) {
if sd.Location == nil {
sd.Location = time.UTC
}
if len(sd.SearchPath.GetPathArray()) == 0 {
sd.SearchPath = sessiondata.DefaultSearchPathForUser(sd.User())
}
}

// newConnExecutor creates a new connExecutor.
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,7 @@ func (ief *InternalDB) newInternalExecutorWithTxn(
if sd == nil {
sd = NewFakeSessionData(sv, "" /* opName */)
sd.UserProto = username.RootUserName().EncodeProto()
sd.SearchPath = sessiondata.DefaultSearchPathForUser(sd.User())
}

schemaChangerState := &SchemaChangerState{
Expand Down
15 changes: 15 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/pg_builtins
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,21 @@ SELECT pg_catalog.set_config('woo', 'woo', false)
query error configuration setting.*not supported
SELECT set_config('vacuum_cost_delay', '0', false)

# Regression test for #117316. Setting an empty search_path should succeed.
query T
SELECT pg_catalog.set_config('search_path', '', false)
----
·

query T
SHOW search_path
----
·

# Reset the search paths for subsequent tests.
statement ok
RESET search_path

# pg_my_temp_schema
#
# Before a temporary schema is created, it returns 0. Afterwards, it returns the
Expand Down
6 changes: 3 additions & 3 deletions pkg/sql/pgwire/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1701,9 +1701,9 @@ func TestParseSearchPathInConnectionString(t *testing.T) {
expectedErr: `option "Ghi" is invalid`,
},
{
desc: "empty search_path is not allowed",
query: `options=-c search_path=`,
expectedErr: `invalid value for parameter "search_path": ""`,
desc: "empty search_path is allowed",
query: `options=-c search_path=`,
expectedSearchPath: ``,
},
{
desc: "unbalanced quotes in search_path are not allowed",
Expand Down
5 changes: 5 additions & 0 deletions pkg/sql/sessiondata/parse_search_path.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ func doParseSearchPathFromString(s string) ([]string, bool) {
result: make([]string, 0, strings.Count(s, ",")),
}

// Empty strings are valid search paths.
if parser.eof() {
return parser.result, true
}

parser.eatWhitespace()
if parser.eof() {
return nil, false
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sessiondata/search_path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ func TestParseSearchPathEdgeCases(t *testing.T) {
expected []string
expectedErr bool
}{
{input: ``, expectedErr: true},
{input: ``, expected: []string{}},
{input: `""`, expected: []string{""}},
{input: ` `, expectedErr: true},
{input: `a, `, expectedErr: true},
Expand Down

0 comments on commit aca59a6

Please sign in to comment.