Skip to content

Commit

Permalink
Merge #54219 #54371
Browse files Browse the repository at this point in the history
54219: sql: allow CONNECTION LIMIT syntax for CREATE DATABASE r=arulajmani a=otan

Resolves #54116.

Release note (sql change): Added the ability to parse the `CONNECTION
LIMIT [=] iconst32` syntax for `CREATE DATABASE`. This is currently a
no-op for -1 (default, unlimited connections), and errors for any
other value.



54371: roachtest: update psycopg test version r=rafiss a=rafiss

We now use a version that is CockroachDB-aware and skips known failing
tests.

Release note: None
Release justification: test only change

Co-authored-by: Oliver Tan <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
  • Loading branch information
3 people committed Sep 15, 2020
3 parents 5f902d0 + bb25412 + 85068dc commit 2ae4b3a
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 931 deletions.
8 changes: 4 additions & 4 deletions docs/generated/sql/bnf/create_database_stmt.bnf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
create_database_stmt ::=
'CREATE' 'DATABASE' database_name opt_with opt_template_clause 'ENCODING' opt_equal non_reserved_word_or_sconst opt_lc_collate_clause opt_lc_ctype_clause
| 'CREATE' 'DATABASE' database_name opt_with opt_template_clause opt_lc_collate_clause opt_lc_ctype_clause
| 'CREATE' 'DATABASE' 'IF' 'NOT' 'EXISTS' database_name opt_with opt_template_clause 'ENCODING' opt_equal non_reserved_word_or_sconst opt_lc_collate_clause opt_lc_ctype_clause
| 'CREATE' 'DATABASE' 'IF' 'NOT' 'EXISTS' database_name opt_with opt_template_clause opt_lc_collate_clause opt_lc_ctype_clause
'CREATE' 'DATABASE' database_name opt_with opt_template_clause 'ENCODING' opt_equal non_reserved_word_or_sconst opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit
| 'CREATE' 'DATABASE' database_name opt_with opt_template_clause opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit
| 'CREATE' 'DATABASE' 'IF' 'NOT' 'EXISTS' database_name opt_with opt_template_clause 'ENCODING' opt_equal non_reserved_word_or_sconst opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit
| 'CREATE' 'DATABASE' 'IF' 'NOT' 'EXISTS' database_name opt_with opt_template_clause opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit
17 changes: 11 additions & 6 deletions docs/generated/sql/bnf/stmt_block.bnf
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,7 @@ unreserved_keyword ::=
| 'CONFIGURATION'
| 'CONFIGURATIONS'
| 'CONFIGURE'
| 'CONNECTION'
| 'CONSTRAINTS'
| 'CONTROLCHANGEFEED'
| 'CONTROLJOB'
Expand Down Expand Up @@ -1225,8 +1226,8 @@ create_changefeed_stmt ::=
'CREATE' 'CHANGEFEED' 'FOR' changefeed_targets opt_changefeed_sink opt_with_options

create_database_stmt ::=
'CREATE' 'DATABASE' database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause
| 'CREATE' 'DATABASE' 'IF' 'NOT' 'EXISTS' database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause
'CREATE' 'DATABASE' database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit
| 'CREATE' 'DATABASE' 'IF' 'NOT' 'EXISTS' database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit

create_index_stmt ::=
'CREATE' opt_unique 'INDEX' opt_concurrently opt_index_name 'ON' table_name opt_using_gin_btree '(' index_params ')' opt_hash_sharded opt_storing opt_interleave opt_partition_by opt_where_clause
Expand Down Expand Up @@ -1684,6 +1685,10 @@ opt_lc_ctype_clause ::=
'LC_CTYPE' opt_equal non_reserved_word_or_sconst
|

opt_connection_limit ::=
'CONNECTION' 'LIMIT' opt_equal signed_iconst
|

opt_unique ::=
'UNIQUE'
|
Expand Down Expand Up @@ -2108,6 +2113,10 @@ opt_equal ::=
'='
|

signed_iconst ::=
'ICONST'
| only_signed_iconst

opt_name ::=
name
|
Expand Down Expand Up @@ -2738,10 +2747,6 @@ geo_shape_type ::=
| 'GEOMETRYCOLLECTION'
| 'GEOMETRY'

signed_iconst ::=
'ICONST'
| only_signed_iconst

char_aliases ::=
'CHAR'
| 'CHARACTER'
Expand Down
21 changes: 3 additions & 18 deletions pkg/cmd/roachtest/psycopg.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,11 @@ package main

import (
"context"
"fmt"
"regexp"
)

var psycopgReleaseTagRegex = regexp.MustCompile(`^(?P<major>\d+)(?:_(?P<minor>\d+)(?:_(?P<point>\d+)(?:_(?P<subpoint>\d+))?)?)?$`)

// TODO(rafi): use a release tag once the commit below appears in a release.
var supportedPsycopgTag = "cecff195fc17a83d593dd62c239aa188883a844e"
var supportedPsycopgTag = "2_8_6"

// This test runs psycopg full test suite against a single cockroach node.
func registerPsycopg(r *testRegistry) {
Expand Down Expand Up @@ -81,20 +78,8 @@ func registerPsycopg(r *testRegistry) {
c,
"https://github.com/psycopg/psycopg2.git",
"/mnt/data1/psycopg",
"master",
node,
); err != nil {
t.Fatal(err)
}

// TODO(rafi): once there's a real release, change the clone step above, and
// remove this.
if err := repeatRunE(
ctx,
c,
supportedPsycopgTag,
node,
"checkout supported tag",
fmt.Sprintf(`cd /mnt/data1/psycopg/ && git fetch --depth=10000 && git checkout %s`, supportedPsycopgTag),
); err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -144,7 +129,7 @@ func registerPsycopg(r *testRegistry) {
Name: "psycopg",
Owner: OwnerAppDev,
Cluster: makeClusterSpec(1),
MinVersion: "v19.1.0",
MinVersion: "v19.2.0",
Tags: []string{`default`, `driver`},
Run: func(ctx context.Context, t *test, c *cluster) {
runPsycopg(ctx, t, c)
Expand Down
896 changes: 4 additions & 892 deletions pkg/cmd/roachtest/psycopg_blocklist.go

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions pkg/sql/create_database.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ func (p *planner) CreateDatabase(ctx context.Context, n *tree.CreateDatabase) (p
}
}

if n.ConnectionLimit != -1 {
return nil, unimplemented.NewWithIssueDetailf(
54241,
"create.db.connection_limit",
"only connection limit -1 is supported, got: %d",
n.ConnectionLimit,
)
}

hasCreateDB, err := p.HasRoleOption(ctx, roleoption.CREATEDB)
if err != nil {
return nil, err
Expand Down
10 changes: 9 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/database
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ CREATE DATABASE b5 TEMPLATE=template0 ENCODING='UTF8' LC_COLLATE='C.UTF-8' LC_CT
statement ok
CREATE DATABASE b6 TEMPLATE template0 ENCODING 'UTF8' LC_COLLATE 'C.UTF-8' LC_CTYPE 'C.UTF-8'

statement ok
CREATE DATABASE b7 WITH CONNECTION LIMIT -1

statement error only connection limit -1 is supported, got: 1
CREATE DATABASE b8 WITH CONNECTION LIMIT = 1

statement ok
CREATE DATABASE c

Expand All @@ -102,6 +108,7 @@ b3
b4
b5
b6
b7
c
defaultdb
postgres
Expand Down Expand Up @@ -141,7 +148,8 @@ DROP DATABASE b2 CASCADE;
DROP DATABASE b3 CASCADE;
DROP DATABASE b4 CASCADE;
DROP DATABASE b5 CASCADE;
DROP DATABASE b6 CASCADE
DROP DATABASE b6 CASCADE;
DROP DATABASE b7 CASCADE

statement error pgcode 42601 empty database name
DROP DATABASE ""
Expand Down
9 changes: 9 additions & 0 deletions pkg/sql/parser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestParse(t *testing.T) {
{`CREATE DATABASE a LC_CTYPE = 'C.UTF-8'`},
{`CREATE DATABASE a LC_CTYPE = 'INVALID'`},
{`CREATE DATABASE a TEMPLATE = 'template0' ENCODING = 'UTF8' LC_COLLATE = 'C.UTF-8' LC_CTYPE = 'INVALID'`},
{`CREATE DATABASE a CONNECTION LIMIT = 13`},
{`CREATE DATABASE IF NOT EXISTS a`},
{`CREATE DATABASE IF NOT EXISTS a TEMPLATE = 'template0'`},
{`CREATE DATABASE IF NOT EXISTS a TEMPLATE = 'invalid'`},
Expand Down Expand Up @@ -1675,6 +1676,14 @@ func TestParse2(t *testing.T) {
`CREATE DATABASE a TEMPLATE = 'template0'`},
{`CREATE DATABASE a TEMPLATE = invalid`,
`CREATE DATABASE a TEMPLATE = 'invalid'`},
{
`CREATE DATABASE a WITH CONNECTION LIMIT = 13`,
`CREATE DATABASE a CONNECTION LIMIT = 13`,
},
{
`CREATE DATABASE a WITH CONNECTION LIMIT -1`,
`CREATE DATABASE a`,
},
{`CREATE TABLE a (b INT) WITH (fillfactor=100)`,
`CREATE TABLE a (b INT8)`},
{`CREATE TABLE a (b INT, UNIQUE INDEX foo (b))`,
Expand Down
26 changes: 22 additions & 4 deletions pkg/sql/parser/sql.y
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func (u *sqlSymUnion) refreshDataOption() tree.RefreshDataOption {
%token <str> CHARACTER CHARACTERISTICS CHECK CLOSE
%token <str> CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
%token <str> COMMITTED COMPACT COMPLETE CONCAT CONCURRENTLY CONFIGURATION CONFIGURATIONS CONFIGURE
%token <str> CONFLICT CONSTRAINT CONSTRAINTS CONTAINS CONTROLCHANGEFEED CONTROLJOB
%token <str> CONFLICT CONNECTION CONSTRAINT CONSTRAINTS CONTAINS CONTROLCHANGEFEED CONTROLJOB
%token <str> CONVERSION CONVERT COPY COVERING CREATE CREATEDB CREATELOGIN CREATEROLE
%token <str> CROSS CUBE CURRENT CURRENT_CATALOG CURRENT_DATE CURRENT_SCHEMA
%token <str> CURRENT_ROLE CURRENT_TIME CURRENT_TIMESTAMP
Expand Down Expand Up @@ -922,6 +922,7 @@ func (u *sqlSymUnion) refreshDataOption() tree.RefreshDataOption {
%type <tree.ValidationBehavior> opt_validate_behavior

%type <str> opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause
%type <int32> opt_connection_limit

%type <tree.IsolationLevel> transaction_iso_level
%type <tree.UserPriority> transaction_user_priority
Expand Down Expand Up @@ -7214,17 +7215,18 @@ transaction_deferrable_mode:
// %Text: CREATE DATABASE [IF NOT EXISTS] <name>
// %SeeAlso: WEBDOCS/create-database.html
create_database_stmt:
CREATE DATABASE database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause
CREATE DATABASE database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit
{
$$.val = &tree.CreateDatabase{
Name: tree.Name($3),
Template: $5,
Encoding: $6,
Collate: $7,
CType: $8,
ConnectionLimit: $9.int32(),
}
}
| CREATE DATABASE IF NOT EXISTS database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause
| CREATE DATABASE IF NOT EXISTS database_name opt_with opt_template_clause opt_encoding_clause opt_lc_collate_clause opt_lc_ctype_clause opt_connection_limit
{
$$.val = &tree.CreateDatabase{
IfNotExists: true,
Expand All @@ -7233,8 +7235,9 @@ create_database_stmt:
Encoding: $9,
Collate: $10,
CType: $11,
ConnectionLimit: $12.int32(),
}
}
}
| CREATE DATABASE error // SHOW HELP: CREATE DATABASE

opt_template_clause:
Expand Down Expand Up @@ -7277,6 +7280,20 @@ opt_lc_ctype_clause:
$$ = ""
}

opt_connection_limit:
CONNECTION LIMIT opt_equal signed_iconst
{
ret, err := $4.numVal().AsInt32()
if err != nil {
return setErr(sqllex, err)
}
$$.val = ret
}
| /* EMPTY */
{
$$.val = int32(-1)
}

opt_equal:
'=' {}
| /* EMPTY */ {}
Expand Down Expand Up @@ -11413,6 +11430,7 @@ unreserved_keyword:
| CONFIGURATION
| CONFIGURATIONS
| CONFIGURE
| CONNECTION
| CONSTRAINTS
| CONTROLCHANGEFEED
| CONTROLJOB
Expand Down
17 changes: 11 additions & 6 deletions pkg/sql/sem/tree/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ import (

// CreateDatabase represents a CREATE DATABASE statement.
type CreateDatabase struct {
IfNotExists bool
Name Name
Template string
Encoding string
Collate string
CType string
IfNotExists bool
Name Name
Template string
Encoding string
Collate string
CType string
ConnectionLimit int32
}

// Format implements the NodeFormatter interface.
Expand All @@ -66,6 +67,10 @@ func (node *CreateDatabase) Format(ctx *FmtCtx) {
ctx.WriteString(" LC_CTYPE = ")
lex.EncodeSQLStringWithFlags(&ctx.Buffer, node.CType, ctx.flags.EncodeFlags())
}
if node.ConnectionLimit != -1 {
ctx.WriteString(" CONNECTION LIMIT = ")
ctx.WriteString(strconv.Itoa(int(node.ConnectionLimit)))
}
}

// IndexElem represents a column with a direction in a CREATE INDEX statement.
Expand Down

0 comments on commit 2ae4b3a

Please sign in to comment.