rfc: computed columns#20735
Conversation
|
Excited to see this RFC. A few questions below. Nothing major. Review status: 0 of 1 files reviewed at latest revision, 7 unresolved discussions, all commit checks successful. docs/RFCS/20171214_computed_columns.md, line 17 at r1 (raw file):
Given that this RFC is about computed columns, I'm not sure why this paragraph is needed here. Perhaps move it to the end of the document under a docs/RFCS/20171214_computed_columns.md, line 32 at r1 (raw file):
We use the term docs/RFCS/20171214_computed_columns.md, line 34 at r1 (raw file):
Why does the primary key require materialized columns? docs/RFCS/20171214_computed_columns.md, line 53 at r1 (raw file):
This column will need to be docs/RFCS/20171214_computed_columns.md, line 124 at r1 (raw file):
Also seems bad to drop a computed column if it is referenced by a partition. docs/RFCS/20171214_computed_columns.md, line 131 at r1 (raw file):
I don't see this as being a significant complication. For non-materialized columns, query planning would likely just expand any references to the column to be the underlying expression. docs/RFCS/20171214_computed_columns.md, line 152 at r1 (raw file):
Are the parentheses really needed for the Comments from Reviewable |
|
Review status: 0 of 1 files reviewed at latest revision, 7 unresolved discussions, some commit checks pending. docs/RFCS/20171214_computed_columns.md, line 17 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
I think the rationale for this paragraph was that the problems this feature solves for JSON were often discussed in terms of computed indexes before this, and this closes the loop on those conversations. It might make more sense to move it to the alternatives section though! docs/RFCS/20171214_computed_columns.md, line 32 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
I don't have any strong feelings on this and I don't think Dan does either, docs/RFCS/20171214_computed_columns.md, line 34 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
It has to be materialized so that it can form the primary index. This is as opposed to a non-materialized column that is part of a secondary index - it doesn't have to be materialized for its existence in the primary index, but it will have to be materialized within the secondary index. It's probably debatable if "materialized" has the same connotation when the value exists in the key or the value of a kv-entry. docs/RFCS/20171214_computed_columns.md, line 53 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
You are correct! Good catch. docs/RFCS/20171214_computed_columns.md, line 124 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
I believe this is covered under whatever usual behaviour exists around dropping columns referenced by partitions, even if they aren't computed. docs/RFCS/20171214_computed_columns.md, line 131 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Ok, sounds good. I'll remove this as a concern. docs/RFCS/20171214_computed_columns.md, line 152 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Good catch - they're required in both cases. Comments from Reviewable |
|
Reviewed 1 of 1 files at r1. docs/RFCS/20171214_computed_columns.md, line 32 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
Views can also be docs/RFCS/20171214_computed_columns.md, line 34 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
(And if it is required, shouldn't it be required for any columns used in a docs/RFCS/20171214_computed_columns.md, line 38 at r1 (raw file):
nit: consider pulling this out into a reference-style link docs/RFCS/20171214_computed_columns.md, line 67 at r1 (raw file):
nit: consider wrapping docs/RFCS/20171214_computed_columns.md, line 89 at r1 (raw file):
I think you should be able to specify CREATE TABLE t (a INT, b INT AS (a + 1) STORED, c);
INSERT INTO t (a, c) VALUES (1, 2) -- Great! Easy!
INSERT INTO t VALUES (1, ???, 2) -- Eek! Yes, implicit column lists are evil, but we should still support an escape hatch so you can specify the columns after a persisted column in a docs/RFCS/20171214_computed_columns.md, line 152 at r1 (raw file): Previously, petermattis (Peter Mattis) wrote…
In my tests they're required for both. Comments from Reviewable |
|
Review status: 0 of 1 files reviewed at latest revision, 10 unresolved discussions, some commit checks pending. docs/RFCS/20171214_computed_columns.md, line 17 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
The way I understood it is that with computed indices, you might expect the SELECT query in the following example to use the index: CREATE TABLE t (a INT, b INT);
CREATE INDEX ON t ((a + b));
SELECT * FROM t WHERE b + a > 10;When in fact it's not trivial to prove that If you force users to create a stored column instead CREATE TABLE t (a INT, b INT, c INT AS (a + b) STORED);
CREATE INDEX ON t (c);it's obvious to the user and the optimizer that docs/RFCS/20171214_computed_columns.md, line 32 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
Didn't realize there was precedent for both docs/RFCS/20171214_computed_columns.md, line 34 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
Yeah, in my mind it's perfectly reasonable that a column used in an index is essentially docs/RFCS/20171214_computed_columns.md, line 124 at r1 (raw file): Previously, justinj (Justin Jaffray) wrote…
I don't think that logic exists yet :S. It should! Comments from Reviewable |
|
|
||
| ```protobuf | ||
| message ColumnDescriptor { | ||
| ... |
There was a problem hiding this comment.
what will its name be?
| CREATE TABLE documents ( | ||
| id STRING PRIMARY KEY AS payload->>'id' PERSISTED, | ||
| payload JSONB | ||
| ) |
There was a problem hiding this comment.
users might prefer using the postgres variant
CREATE TABLE documents (
payload JSONB
UNIQUE (payload->>'id')
)
I see the JSON use case as not necessarily needing the computed column but a computed index.
|
|
||
| The grammar for a computed column is `column_name <type> AS <expr> | ||
| [PERSISTED]`, where `<expr>` is a pure function of non-computed columns in the | ||
| same table. `PERSISTED` indicates a materialized computed column and is |
There was a problem hiding this comment.
Do we really need PERSISTED ?I ask because it appears that we're only using it for indexes.
|
Great RFC! Will you support Reviewed 1 of 1 files at r2. docs/RFCS/20171214_computed_columns.md, line 32 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
For this syntax bikeshedding to be successful, I think it's important to examine what other databases do. MySQL: Looks like I think we should support (whoops, didn't realize you did this analysis at the bottom - please mention that up here!) docs/RFCS/20171214_computed_columns.md, line 34 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
nit: docs/RFCS/20171214_computed_columns.md, line 67 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
+1 docs/RFCS/20171214_computed_columns.md, line 89 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
Agreed that docs/RFCS/20171214_computed_columns.md, line 152 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
MySQL also supports the docs/RFCS/20171214_computed_columns.md, line 14 at r2 (raw file):
Can we pick a terminology here? the industry standard seems to be stored/persisted vs virtual. I suggest we do the same. docs/RFCS/20171214_computed_columns.md, line 37 at r2 (raw file):
nit: "this columns" seems to be incorrect grammar. docs/RFCS/20171214_computed_columns.md, line 93 at r2 (raw file):
Just a note - don't forget to update docs/RFCS/20171214_computed_columns.md, line 99 at r2 (raw file): Previously, vivekmenezes wrote…
Seems like docs/RFCS/20171214_computed_columns.md, line 102 at r2 (raw file):
Please keep the terminology consistent as mentioned above. (and throughout - I think we should globally s/materialized/stored/ if we decided on stored as the syntax word) Comments from Reviewable |
|
LGTM modulo resolution of the points already raised. 👍 on STORED/VIRTUAL vs PERSISTED/nothing. Review status: all files reviewed at latest revision, 18 unresolved discussions, all commit checks successful. docs/RFCS/20171214_computed_columns.md, line 141 at r2 (raw file):
"Computed indexes solve the same problems as computed indexes" - tautology Comments from Reviewable |
|
Reviewed 1 of 1 files at r2. Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 18 unresolved discussions, all commit checks successful. docs/RFCS/20171214_computed_columns.md, line 32 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. docs/RFCS/20171214_computed_columns.md, line 34 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
We discussed a bit in person - I think we've settled on the position that since a column in the primary key will need to be "stored" in the primary index regardless of whether it's specified, we'd prefer to require them to be stored in that case. This matches MySQL's behaviour. docs/RFCS/20171214_computed_columns.md, line 38 at r1 (raw file): Previously, benesch (Nikhil Benesch) wrote…
Done. docs/RFCS/20171214_computed_columns.md, line 67 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. docs/RFCS/20171214_computed_columns.md, line 89 at r1 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
I actually missed this syntax! That's useful and I've included it now. docs/RFCS/20171214_computed_columns.md, line 14 at r2 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. docs/RFCS/20171214_computed_columns.md, line 29 at r2 (raw file): Previously, vivekmenezes wrote…
It's true for our uses in indexes we could get away with only one of persisted/not persisted, and we're only planning to implement persisted for the time being (just because it seems easier to implement), this RFC covers both for completeness. docs/RFCS/20171214_computed_columns.md, line 37 at r2 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. docs/RFCS/20171214_computed_columns.md, line 69 at r2 (raw file): Previously, vivekmenezes wrote…
Yeah, that's correct, but we decided that for JSON this was a simpler implementation at the moment, and has some overlap with the features needed by partitioning. docs/RFCS/20171214_computed_columns.md, line 102 at r2 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. docs/RFCS/20171214_computed_columns.md, line 141 at r2 (raw file): Previously, knz (kena) wrote…
Fixed. Comments from Reviewable |
|
Review status: 0 of 1 files reviewed at latest revision, 17 unresolved discussions, some commit checks pending. docs/RFCS/20171214_computed_columns.md, line 15 at r3 (raw file):
what about docs/RFCS/20171214_computed_columns.md, line 28 at r3 (raw file):
Shouldn't this be Comments from Reviewable |
|
Reviewed 1 of 1 files at r3. Comments from Reviewable |
|
LGTM! |
Release note: None
|
Entering final comment period - targeting merge on Thursday! Review status: all files reviewed at latest revision, 17 unresolved discussions, all commit checks successful. docs/RFCS/20171214_computed_columns.md, line 15 at r3 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Done. docs/RFCS/20171214_computed_columns.md, line 28 at r3 (raw file): Previously, jordanlewis (Jordan Lewis) wrote…
Yes, good point! Comments from Reviewable |
|
Reviewed 1 of 1 files at r4. Comments from Reviewable |
|
Thanks for the reviews everyone! |
Release note: None