Skip to content

Commit

Permalink
sql: desugar "TIMESTAMP WITH TIME ZONE" to "TIMESTAMPTZ"
Browse files Browse the repository at this point in the history
Prior to this patch the canonical name for the timestamptz type in
CockroachDB was "TIMESTAMP WITH TIME ZONE" with spaces and all
glorious 24 characters.

This is unfortunate because this is a pretty common type, and is
moreover used to disambiguate the return type of `now()` and thus will
be emitted pretty often in distsql physical plans. Having such a long
type name is unnecessary and indeed adds 50%+ storage, communication
and parsing overhead for every occurrence of this type in
distsql plans.

This patch shortens the canonical CockroachDB name to "TIMESTAMPTZ".

The representation of the type in introspection tables (pg_catalog,
information_schema) is unaffected.

Release note: None
  • Loading branch information
knz committed Aug 23, 2018
1 parent f635e06 commit f7708e9
Show file tree
Hide file tree
Showing 16 changed files with 180 additions and 178 deletions.
2 changes: 1 addition & 1 deletion docs/RFCS/20170317_settings_table.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ A new system.settings table, keyed by string settings names would be created.
CREATE TABLE system.settings (
name STRING PRIMARY KEY,
value STRING,
updated TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
updated TIMESTAMPTZ DEFAULT NOW() NOT NULL,
valueType char NOT NULL DEFAULT 's',
)
```
Expand Down
8 changes: 5 additions & 3 deletions pkg/cli/dump_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func TestDumpRandom(t *testing.T) {
fr real,
d date,
m timestamp,
mtz timestamptz,
n interval,
o bool,
e decimal,
Expand All @@ -212,7 +213,7 @@ func TestDumpRandom(t *testing.T) {
u uuid,
ip inet,
j json,
PRIMARY KEY (rowid, i, si, bi, f, fr, d, m, n, o, e, s, b, u, ip)
PRIMARY KEY (rowid, i, si, bi, f, fr, d, m, mtz, n, o, e, s, b, u, ip)
);
SET extra_float_digits = 3;
`, nil); err != nil {
Expand Down Expand Up @@ -287,6 +288,7 @@ func TestDumpRandom(t *testing.T) {
f, // fr
d,
m,
m,
[]byte(n), // intervals come out as `[]byte`s
o,
[]byte(e), // decimals come out as `[]byte`s
Expand All @@ -296,14 +298,14 @@ func TestDumpRandom(t *testing.T) {
[]byte(ip.String()),
[]byte(j.String()),
}
if err := conn.Exec("INSERT INTO d.t VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16)", vals); err != nil {
if err := conn.Exec("INSERT INTO d.t VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)", vals); err != nil {
t.Fatal(err)
}
generatedRows = append(generatedRows, vals[1:])
}

check := func(table string) {
q := fmt.Sprintf("SELECT i, si, bi, f, fr, d, m, n, o, e, s, b, u, ip, j FROM %s ORDER BY rowid", table)
q := fmt.Sprintf("SELECT i, si, bi, f, fr, d, m, mtz, n, o, e, s, b, u, ip, j FROM %s ORDER BY rowid", table)
nrows, err := conn.Query(q, nil)
if err != nil {
t.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/testdata/dump/row
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ CREATE TABLE t (
ip INET NULL,
j JSONB NULL,
ary STRING[] NULL,
tz TIMESTAMP WITH TIME ZONE NULL,
tz TIMESTAMPTZ NULL,
e1 DECIMAL(2) NULL,
e2 DECIMAL(2,1) NULL,
s1 STRING(1) NULL,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/coltypes/timedate.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (node *TTimestampTZ) TypeName() string { return "TIMESTAMPTZ" }

// Format implements the ColTypeFormatter interface.
func (node *TTimestampTZ) Format(buf *bytes.Buffer, f lex.EncodeFlags) {
buf.WriteString("TIMESTAMP WITH TIME ZONE")
buf.WriteString(node.TypeName())
}

// TInterval represents an INTERVAL type
Expand Down
4 changes: 2 additions & 2 deletions pkg/sql/copy_in_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestCopyNullInfNaN(t *testing.T) {
e DECIMAL NULL,
u UUID NULL,
ip INET NULL,
tz TIMESTAMP WITH TIME ZONE NULL
tz TIMESTAMPTZ NULL
);
`); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -151,7 +151,7 @@ func TestCopyRandom(t *testing.T) {
b BYTES,
u UUID,
ip INET,
tz TIMESTAMP WITH TIME ZONE
tz TIMESTAMPTZ
);
SET extra_float_digits = 3; -- to preserve floats entirely
`); err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/sql/logictest/testdata/logic_test/alter_column_type
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ ALTER TABLE t ALTER s TYPE BYTES, ALTER sl TYPE STRING(6), ALTER ts TYPE TIMESTA
query TTBTTTB colnames
SHOW COLUMNS FROM t
----
column_name data_type is_nullable column_default generation_expression indices is_hidden
s BYTES true NULL · {} false
sl STRING(6) true NULL · {} false
t TIME true NULL · {} false
ts TIMESTAMP WITH TIME ZONE true NULL · {} false
rowid INT false unique_rowid() · {"primary"} true
column_name data_type is_nullable column_default generation_expression indices is_hidden
s BYTES true NULL · {} false
sl STRING(6) true NULL · {} false
t TIME true NULL · {} false
ts TIMESTAMPTZ true NULL · {} false
rowid INT false unique_rowid() · {"primary"} true

query TTTT
SELECT * FROM t
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/logictest/testdata/logic_test/collatedstring
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ SELECT '2017-01-10 16:05:50.734049+00:00' COLLATE en::TIMESTAMP
2017-01-10 16:05:50.734049 +0000 +0000

query T
SELECT '2017-01-10 16:05:50.734049+00:00' COLLATE en::TIMESTAMP WITH TIME ZONE
SELECT '2017-01-10 16:05:50.734049+00:00' COLLATE en::TIMESTAMPTZ
----
2017-01-10 16:05:50.734049 +0000 +0000

Expand Down
18 changes: 9 additions & 9 deletions pkg/sql/logictest/testdata/logic_test/datetime
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ statement ok
CREATE TABLE u (
a BIGINT PRIMARY KEY,
b TIMESTAMP,
c TIMESTAMP WITH TIME ZONE,
c TIMESTAMPTZ,
d DATE,
e INTERVAL
)
Expand Down Expand Up @@ -176,7 +176,7 @@ BEGIN TRANSACTION
statement ok
CREATE TABLE kv (
k CHAR PRIMARY KEY,
v TIMESTAMP WITH TIME ZONE
v TIMESTAMPTZ
)

statement ok
Expand Down Expand Up @@ -336,9 +336,9 @@ statement ok
CREATE TABLE ex (
k BIGINT PRIMARY KEY,
element STRING,
input TIMESTAMP WITH TIME ZONE,
input TIMESTAMPTZ,
extract_result INT,
date_trunc_result TIMESTAMP WITH TIME ZONE
date_trunc_result TIMESTAMPTZ
)

statement ok
Expand Down Expand Up @@ -907,17 +907,17 @@ statement ok
CREATE TABLE tz (
a INT PRIMARY KEY,
b TIMESTAMP,
c TIMESTAMP WITH TIME ZONE,
c TIMESTAMPTZ,
d TIMESTAMPTZ
)

query TTBTTTB
SHOW COLUMNS FROM tz
----
a INT false NULL · {"primary"} false
b TIMESTAMP true NULL · {} false
c TIMESTAMP WITH TIME ZONE true NULL · {} false
d TIMESTAMP WITH TIME ZONE true NULL · {} false
a INT false NULL · {"primary"} false
b TIMESTAMP true NULL · {} false
c TIMESTAMPTZ true NULL · {} false
d TIMESTAMPTZ true NULL · {} false

statement ok
INSERT INTO tz VALUES
Expand Down
Loading

0 comments on commit f7708e9

Please sign in to comment.