Use faster set for column IDs in schemaexpr#49819
Use faster set for column IDs in schemaexpr#49819craig[bot] merged 2 commits intocockroachdb:masterfrom
Conversation
RaduBerinde
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 1 of 0 LGTMs obtained (waiting on @mgartner, @mjibson, @RaduBerinde, and @rytaft)
pkg/sql/schemaexpr/column.go, line 154 at r1 (raw file):
func replaceVars( desc *sqlbase.MutableTableDescriptor, rootExpr tree.Expr, ) (tree.Expr, util.FastIntSet, error) {
I'd name this return arg so it's more evident what it is, e.g. _ tree.Expr, columnIDs util.FastIntSet, _ error
pkg/sql/schemaexpr/computed_column.go, line 61 at r1 (raw file):
} var dependencies util.FastIntSet
[nit] Unfortunately it's not easy to tell what the numbers in the set are, maybe depColumnIDs. Or, if there is or we expect wider-spread usage of sets of sqlbase.ColumnID, we may want to make a nicely typed wrapper like opt.ColSet.
65ccc0a to
ae9c179
Compare
mgartner
left a comment
There was a problem hiding this comment.
Reviewable status:
complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @mjibson, @RaduBerinde, and @rytaft)
pkg/sql/schemaexpr/column.go, line 154 at r1 (raw file):
Previously, RaduBerinde wrote…
I'd name this return arg so it's more evident what it is, e.g.
_ tree.Expr, columnIDs util.FastIntSet, _ error
Now that I've added a typed wrapper, I'm thinking this is OK to be unnamed. Do you agree?
pkg/sql/schemaexpr/computed_column.go, line 61 at r1 (raw file):
Previously, RaduBerinde wrote…
[nit] Unfortunately it's not easy to tell what the numbers in the set are, maybe
depColumnIDs. Or, if there is or we expect wider-spread usage of sets of sqlbase.ColumnID, we may want to make a nicely typed wrapper likeopt.ColSet.
Good point. I've updated the name, and I've also created the sqlbase.ColSet typed wrapper, since it looks like there's quite a few places that could use it.
Is that name good, or would sqlbase.ColIdSet or sqlbase.ColumnIDSet be better?
My quick searching of some places this could be used:
ae9c179 to
c63ded6
Compare
|
pkg/sql/schemaexpr/computed_column.go, line 61 at r1 (raw file): Previously, mgartner (Marcus Gartner) wrote…
Nice! Maybe TableColSet? because you can only reasonably use it for columns of a single table (ids are unique only within each table) |
c63ded6 to
166d492
Compare
There are numerous places where a `map[sqlbase.ColumnID]struct{}` or a
`util.FastIntSet` is used to represent a set of `sqlbase.ColumnID`. This
commit adds a typed wrapper around `util.FastIntSet` which is an
efficient and ergonomic replacement for maps and `util.FastIntSet`.
Release note: None
166d492 to
3896a63
Compare
| import "github.com/cockroachdb/cockroach/pkg/util" | ||
|
|
||
| // TableColSet efficiently stores an unordered set of column ids. | ||
| type TableColSet struct { |
There was a problem hiding this comment.
What is the reason for wrapping util.FastIntSet here? As far as I can tell all the methods just call into util.FastIntSet.
There was a problem hiding this comment.
It's so it's strongly typed, which makes it evident what it stores and you don't have to cast ColumnIDs to ints and back.
There was a problem hiding this comment.
I guess, but it also feels like a good amount of duplication.
There was a problem hiding this comment.
After working without a wrapper for opt.ColSet for a few releases (until Go implemented mid-stack inlining) I can tell you that the duplication is worth it.
There was a problem hiding this comment.
Sounds good -- i haven't had to use this extensively to really have an opinion.
There was a problem hiding this comment.
I think the bit of duplication is worth it for the clarity and conciseness it provides when using TableColSet.
b44a672 to
0a54fd8
Compare
rytaft
left a comment
There was a problem hiding this comment.
Reviewed 5 of 5 files at r2, 5 of 6 files at r3, 2 of 2 files at r4.
Reviewable status:complete! 1 of 0 LGTMs obtained (and 1 stale) (waiting on @mgartner, @mjibson, @RaduBerinde, and @rohany)
This commit replaces maps used as sets of integers with sqlbase.TableColSet because it is a more efficient set implementation. Release note: None
0a54fd8 to
f61f13e
Compare
|
bors r+ |
Merge conflict (retrying...) |
Build succeeded |


sqlbase: add ColSet wrapper for util.FastIntSet of ColumnID
There are numerous places where a
map[sqlbase.ColumnID]struct{}or autil.FastIntSetis used to represent a set ofsqlbase.ColumnID. Thiscommit adds a typed wrapper around
util.FastIntSetwhich is anefficient and ergonimic replacement for maps and
util.FastIntSet.Release note: None
schemaexpr: use sqlbase.ColSet instead of maps
This commit replaces maps used as sets of integers with sqlbase.ColSet
because it is a more efficient set implementation.
Release note: None