Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql, *: make CockroachDB understand schema names #22753

Merged
merged 1 commit into from Feb 16, 2018

Conversation

Projects
None yet
3 participants
@knz
Copy link
Member

commented Feb 15, 2018

Result of rebasing #22371 off master.

Fixes #22700.
Implements #21456.

"Why":

Prior to this patch, CockroachDB only recognized names of the form
"db.tbl", like MySQL, whereas PostgreSQL compatibility mandates that
"db.public.tbl" be also valid. This needed a change.

"What"

The visible tip of this iceberg patch is as follows:

  • new name resolution functions which are more correct and more easy
    to use than the previous code!

    Use Normalize() on a TableName, then ResolveExistingObject()
    or ResolveTargetObject().

  • this in turn relies on generic, well-abstracted name resolution
    algorithms in sem/tree/name_resolution.go, the definition
    of which closely follows the specs in the accompanying RFC (#21456).

    This handles the pg syntax for catalog and schema names, together
    with compatibility rules with CockroachDB v1.x.

  • a new schema accessor interface that truly encapsulates schema access!
    Check out the gorgeous documentation in sql/schema_accessors.go.

    In particular:

    • planner now implements a new interface SchemaResolver. Use it.

    • if you are not happy with SchemaResolver directly, use
      SchemaAccessor or its various consistuent interfaces.

      Depending on whether virtual schemas are to be considered, consider
      alternatively planner.LogicalSchemaAccessor() and
      planner.PhysicalSchemaAccessor().

One may be surprised to see this schema accessor work happen in the
same patch. This was, unfortunately, a requirement to successfully
plug catalog and schema name resolution in all the right places.
Also, it incidentally answers a long-standing demand for a better
interface to access descriptors.

"How"

The itinerary to achieve this brought me through the following steps:

  • the various name resolution algorithms are concentrated in a new
    file sql/sem/tree/name_resolution.go. They use abstract
    interfaces to interface with the "name provider": database, table,
    column things coming from the database.

  • in the process of writing the name resolution algorithms, I found
    that our previous understanding of name resolution was problematic:

    • the previous code assumed it was always possible to "qualify a
      name using the current database" by just looking at the name
      itself and the current database, without any additional
      information.

      In contrast, the correct qualification algorithms requires both
      the current database, the search path, and descriptor
      lookups.

      This is why this patch fuses all occurrences of separate
      "qualification" and "resolution" phases together.

      Before: tn = tn.QualifyWithDatabase(tcurDb); desc = MustGetDesc(tn)

      After: desc = ResolveExistingObject(p, tn)

    • the resolution code was pushing a VirtualTabler very deep in the
      lookup routines, with the mistaken understanding that
      VirtualTabler is able to respond to requests for database names.

      In contrast, VirtualTabler really has nothing to do with database
      names, and the corresponding code had to get rid of it.

      This was the first motivation for implementing new schema accessor
      interfaces.

    • the path to decide whether to use cached or non-cached descriptors
      was very hard to read; in many instances the code was using
      uncached descriptors where cached descriptors would be needed
      instead. The various APIs were a mess, and information needed to
      decide whether a lookup was possible or not was not available at
      the right level(s) of abstraction.

      This was the second motivation for implementing new schema accessor
      interfaces.

  • Once this all was said done, the various consumers of name
    resolution had to implement the interfaces. They are:

    • resolution of zone specifiers;
    • resolution of target names for CCL statements;
    • resolution of names (both existing and targets) in the sql package;
    • some testing code in sql/opt and sql/opt/build.

Release note (sql change): CockroachDB now recognizes the syntax
db.public.tbl in addition to db.tbl, for better compatibility with
PostgreSQL. The handling of the session variable search_path, as
well as that of the built-in functions current_schemas() and
current_schema(), is now closer to that of PostgreSQL.

Release note (sql change): SHOW TABLES FROM can now inspect the tables
of a specific shema, for example SHOW TABLES FROM db.public or SHOW TABLES FROM db.pg_catalog.

Release note (sql change): SHOW GRANTS now also shows the schema of
the databases and tables.

@knz knz requested review from cockroachdb/cli-prs as code owners Feb 15, 2018

@cockroach-teamcity

This comment has been minimized.

Copy link
Member

commented Feb 15, 2018

This change is Reviewable

@knz knz force-pushed the knz:20180202-schema-proto branch 11 times, most recently from 528adaf to b0d2d32 Feb 15, 2018

@knz knz requested a review from cockroachdb/sql-wiring-prs as a code owner Feb 16, 2018

@knz knz force-pushed the knz:20180202-schema-proto branch 2 times, most recently from da47831 to fa6797e Feb 16, 2018

sql, *: make CockroachDB understand schema names
"Why":

Prior to this patch, CockroachDB only recognized names of the form
"db.tbl", like MySQL, whereas PostgreSQL compatibility mandates that
"db.public.tbl" be also valid. This needed a change.

**What:**

The visible tip of this iceberg patch is as follows:

- new name resolution functions which are more correct and more easy
  to use than the previous code!

  Use `Normalize()` on a `TableName`, then `ResolveExistingObject()`
  or `ResolveTargetObject()`.

- this in turn relies on generic, well-abstracted name resolution
  algorithms in `sem/tree/name_resolution.go`, the definition
  of which closely follows the specs in the accompanying RFC.

  This handles the pg syntax for catalog and schema names, together
  with compatibility rules with CockroachDB v1.x.

- a new schema accessor interface that truly encapsulates schema access!
  Check out the gorgeous documentation in `sql/schema_accessors.go`.

  In particular:

  - `planner` now implements a new interface `SchemaResolver`. Use it.
  - if you are not happy with `SchemaResolver` directly, use
    `SchemaAccessor` or its various consistuent interfaces.

    Depending on whether virtual schemas are to be considered, consider
    alternatively `planner.LogicalSchemaAccessor()` and
    `planner.PhysicalSchemaAccessor()`.

One may be surprised to see this schema accessor work happen in the
same patch. This was, unfortunately, a requirement to successfully
plug catalog and schema name resolution in all the right places.
Also, it incidentally answers a long-standing demand for a better
interface to access descriptors.

**How:**

The itinerary to achieve this brought me through the following steps:

- the various name resolution algorithms are concentrated in a new
  file `sql/sem/tree/name_resolution.go`. They use abstract
  interfaces to interface with the "name provider": database, table,
  column things coming from the database.

- in the process of writing the name resolution algorithms, I found
  that our previous understanding of name resolution was problematic:

  - the previous code assumed it was always possible to "qualify a
    name using the current database" by just looking at the name
    itself and the current database, without any additional
    information.

    In contrast, the correct qualification algorithms requires both
    the current database, the search path, and descriptor
    lookups.

    This is why this patch fuses all occurrences of separate
    "qualification" and "resolution" phases together.

    Before: `tn = tn.QualifyWithDatabase(tcurDb); desc = MustGetDesc(tn)`

    After: `desc = ResolveExistingObject(p, tn)`

  - the resolution code was pushing a `VirtualTabler` very deep in the
    lookup routines, with the mistaken understanding that
    VirtualTabler is able to respond to requests for database names.

    In contrast, VirtualTabler really has nothing to do with database
    names, and the corresponding code had to get rid of it.

    This was the first motivation for implementing new schema accessor
    interfaces.

  - the path to decide whether to use cached or non-cached descriptors
    was very hard to read; in many instances the code was using
    uncached descriptors where cached descriptors would be needed
    instead. The various APIs were a mess, and information needed to
    decide whether a lookup was possible or not was not available at
    the right level(s) of abstraction.

    This was the second motivation for implementing new schema accessor
    interfaces.

- Once this all was said done, the various consumers of name
  resolution had to implement the interfaces. They are:

  - resolution of zone specifiers;
  - resolution of target names for CCL statements;
  - resolution of names (both existing and targets) in the `sql` package;
  - some testing code in `sql/opt` and `sql/opt/build`.
  - the virtual schemas and tables.

Release note (sql change): CockroachDB now recognizes the syntax
`db.public.tbl` in addition to `db.tbl`, for better compatibility with
PostgreSQL. The handling of the session variable `search_path`, as
well as that of the built-in functions `current_schemas()` and
`current_schema()`, is now closer to that of PostgreSQL.

Release note (sql change): SHOW TABLES FROM can now inspect the tables
of a specific shema, for example `SHOW TABLES FROM db.public` or `SHOW
TABLES FROM db.pg_catalog`.

Release note (sql change): SHOW GRANTS now also shows the schema of
the databases and tables.

@knz knz force-pushed the knz:20180202-schema-proto branch from fa6797e to 15b73e3 Feb 16, 2018

@knz knz requested a review from cockroachdb/build-prs as a code owner Feb 16, 2018

@knz

This comment has been minimized.

Copy link
Member Author

commented Feb 16, 2018

Benchmark diffs:

name                                                       old time/op    new time/op    delta
Select1/Cockroach-16                                         72.9µs ± 5%    72.8µs ± 2%     ~     (p=0.905 n=5+4)
Select2/Cockroach-16                                          726µs ± 1%     754µs ± 2%   +3.84%  (p=0.008 n=5+5)
Select3/Cockroach-16                                          777µs ± 1%     790µs ± 0%   +1.55%  (p=0.008 n=5+5)
Count/Cockroach-16                                           38.2ms ± 1%    37.7ms ± 0%   -1.34%  (p=0.008 n=5+5)
Sort/Cockroach-16                                             151ms ± 1%     151ms ± 1%     ~     (p=0.556 n=5+4)
SQL/Cockroach/Delete/count=1-16                               356µs ± 2%     357µs ± 1%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Delete/count=10-16                              654µs ± 3%     649µs ± 3%     ~     (p=0.548 n=5+5)
SQL/Cockroach/Delete/count=100-16                            3.39ms ± 5%    3.37ms ± 4%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Delete/count=1000-16                           35.9ms ± 4%    35.7ms ± 4%     ~     (p=0.690 n=5+5)
SQL/Cockroach/Insert/count=1-16                               428µs ± 5%     434µs ± 6%     ~     (p=0.690 n=5+5)
SQL/Cockroach/Insert/count=10-16                             1.41ms ±14%    1.43ms ±10%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Insert/count=100-16                            7.69ms ± 6%    7.80ms ±16%     ~     (p=0.841 n=5+5)
SQL/Cockroach/Insert/count=1000-16                           70.2ms ± 7%    65.1ms ±12%     ~     (p=0.095 n=5+5)
SQL/Cockroach/InsertDistinct/count=1-16                      4.28ms ±23%    4.38ms ± 3%     ~     (p=0.310 n=5+5)
SQL/Cockroach/InsertDistinct/count=10-16                      904µs ± 5%     924µs ± 5%     ~     (p=0.421 n=5+5)
SQL/Cockroach/InsertDistinct/count=100-16                    1.60ms ± 3%    1.60ms ± 8%     ~     (p=0.310 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=1-16                      509µs ±11%     505µs ±11%     ~     (p=0.841 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=5-16                      681µs ±15%     673µs ±16%     ~     (p=0.690 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=10-16                     897µs ± 6%     924µs ± 1%     ~     (p=0.056 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=1-16                    1.29ms ± 2%    1.29ms ± 2%     ~     (p=0.690 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=5-16                    3.41ms ± 7%    3.33ms ± 2%     ~     (p=0.421 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=10-16                   4.61ms ± 4%    4.55ms ± 1%     ~     (p=0.310 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=1-16                   8.98ms ± 6%    8.88ms ± 9%     ~     (p=1.000 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=5-16                   29.4ms ±11%    30.2ms ±15%     ~     (p=0.548 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=10-16                  41.1ms ± 3%    40.3ms ± 2%     ~     (p=0.310 n=5+5)
SQL/Cockroach/InsertFK/count=1000/nFks=1-16                  95.3ms ±14%    94.5ms ±15%     ~     (p=1.000 n=5+5)
SQL/Cockroach/InsertFK/count=1000/nFks=5-16                   393ms ± 9%     391ms ±11%     ~     (p=1.000 n=5+5)
SQL/Cockroach/InsertFK/count=1000/nFks=10-16                  476ms ±16%     490ms ±11%     ~     (p=0.548 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=1-16                 451µs ± 1%     463µs ± 4%     ~     (p=0.151 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=10-16               2.14ms ± 4%    2.14ms ± 4%     ~     (p=1.000 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=100-16              18.1ms ± 8%    17.8ms ±10%     ~     (p=0.310 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=1000-16              209ms ± 1%     214ms ± 2%     ~     (p=0.056 n=5+5)
SQL/Cockroach/InterleavedSelect/count=1-16                    307µs ± 1%     313µs ± 4%   +2.19%  (p=0.032 n=5+5)
SQL/Cockroach/InterleavedSelect/count=10-16                   321µs ± 1%     324µs ± 2%     ~     (p=0.548 n=5+5)
SQL/Cockroach/InterleavedSelect/count=100-16                  450µs ± 2%     453µs ± 2%     ~     (p=0.548 n=5+5)
SQL/Cockroach/InterleavedSelect/count=1000-16                1.89ms ± 1%    1.90ms ± 1%     ~     (p=0.413 n=4+5)
SQL/Cockroach/TrackChoices/count=1-16                         337µs ± 3%     347µs ± 3%     ~     (p=0.095 n=5+5)
SQL/Cockroach/TrackChoices/count=10-16                        107µs ± 2%     106µs ± 3%     ~     (p=0.571 n=5+5)
SQL/Cockroach/TrackChoices/count=100-16                      77.9µs ± 5%    81.1µs ± 2%     ~     (p=0.222 n=5+5)
SQL/Cockroach/TrackChoices/count=1000-16                     79.8µs ± 3%    81.6µs ±23%     ~     (p=0.310 n=5+5)
SQL/Cockroach/Update/count=1-16                               376µs ± 1%     382µs ± 1%   +1.74%  (p=0.032 n=5+5)
SQL/Cockroach/Update/count=10-16                              660µs ±21%     631µs ± 5%     ~     (p=0.841 n=5+5)
SQL/Cockroach/Update/count=100-16                            2.92ms ± 1%    2.89ms ± 2%     ~     (p=0.421 n=5+5)
SQL/Cockroach/Update/count=1000-16                           23.6ms ±15%    22.0ms ± 1%   -6.57%  (p=0.008 n=5+5)
SQL/Cockroach/Upsert/count=1-16                               854µs ± 1%     836µs ± 1%   -2.10%  (p=0.008 n=5+5)
SQL/Cockroach/Upsert/count=10-16                             1.66ms ± 1%    1.54ms ± 1%   -7.03%  (p=0.016 n=4+5)
SQL/Cockroach/Upsert/count=100-16                            4.81ms ± 2%    4.59ms ± 1%   -4.47%  (p=0.008 n=5+5)
SQL/Cockroach/Upsert/count=1000-16                           38.0ms ± 1%    36.3ms ± 1%   -4.47%  (p=0.008 n=5+5)
Scan/Cockroach/count=1/limit=0-16                             231µs ± 1%     232µs ± 1%     ~     (p=0.548 n=5+5)
Scan/Cockroach/count=1/limit=1-16                             238µs ± 1%     239µs ± 1%     ~     (p=0.310 n=5+5)
Scan/Cockroach/count=1/limit=10-16                            236µs ± 1%     238µs ± 1%     ~     (p=0.151 n=5+5)
Scan/Cockroach/count=1/limit=100-16                           238µs ± 1%     238µs ± 1%     ~     (p=1.000 n=5+5)
Scan/Cockroach/count=10/limit=0-16                            242µs ± 1%     241µs ± 1%     ~     (p=0.548 n=5+5)
Scan/Cockroach/count=10/limit=1-16                            286µs ± 1%     288µs ± 1%     ~     (p=0.413 n=4+5)
Scan/Cockroach/count=10/limit=10-16                           246µs ± 1%     249µs ± 1%   +1.10%  (p=0.032 n=5+5)
Scan/Cockroach/count=10/limit=100-16                          246µs ± 1%     248µs ± 1%     ~     (p=0.222 n=5+5)
Scan/Cockroach/count=100/limit=0-16                           345µs ± 1%     346µs ± 2%     ~     (p=0.548 n=5+5)
Scan/Cockroach/count=100/limit=1-16                           310µs ± 0%     312µs ± 0%   +0.46%  (p=0.032 n=5+5)
Scan/Cockroach/count=100/limit=10-16                          318µs ± 0%     322µs ± 1%   +0.99%  (p=0.032 n=5+5)
Scan/Cockroach/count=100/limit=100-16                         348µs ± 1%     354µs ± 1%   +1.82%  (p=0.008 n=5+5)
Scan/Cockroach/count=1000/limit=0-16                         1.50ms ± 1%    1.51ms ± 1%     ~     (p=0.095 n=5+5)
Scan/Cockroach/count=1000/limit=1-16                          548µs ± 1%     547µs ± 1%     ~     (p=0.690 n=5+5)
Scan/Cockroach/count=1000/limit=10-16                         559µs ± 0%     561µs ± 0%     ~     (p=0.095 n=5+5)
Scan/Cockroach/count=1000/limit=100-16                        640µs ± 1%     643µs ± 1%     ~     (p=0.548 n=5+5)
Scan/Cockroach/count=10000/limit=0-16                        8.33ms ± 1%    8.58ms ± 1%   +2.96%  (p=0.008 n=5+5)
Scan/Cockroach/count=10000/limit=1-16                         544µs ± 1%     545µs ± 0%     ~     (p=0.421 n=5+5)
Scan/Cockroach/count=10000/limit=10-16                        554µs ± 1%     555µs ± 1%     ~     (p=1.000 n=5+5)
Scan/Cockroach/count=10000/limit=100-16                       674µs ± 2%     663µs ± 1%     ~     (p=0.310 n=5+5)
ScanFilter/Cockroach/count1=25/count2=400/limit=1-16          455µs ± 2%     411µs ± 2%   -9.71%  (p=0.008 n=5+5)
ScanFilter/Cockroach/count1=25/count2=400/limit=10-16         475µs ± 1%     432µs ± 1%   -9.13%  (p=0.008 n=5+5)
ScanFilter/Cockroach/count1=25/count2=400/limit=50-16        1.50ms ± 1%    1.46ms ± 1%   -2.28%  (p=0.016 n=5+5)
OrderBy/Cockroach/count=100000/limit=10/distinct=false-16    80.4ms ± 1%    80.7ms ± 2%     ~     (p=0.841 n=5+5)
OrderBy/Cockroach/count=100000/limit=10/distinct=true-16      188ms ± 9%     182ms ±10%     ~     (p=0.222 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=10-16            3.04ms ± 1%    3.30ms ± 2%   +8.81%  (p=0.008 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=100-16           3.23ms ± 2%    3.52ms ± 1%   +9.05%  (p=0.008 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=1000-16          4.16ms ± 2%    4.44ms ± 3%   +6.65%  (p=0.008 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=10000-16         12.1ms ±11%    12.2ms ± 9%     ~     (p=1.000 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=100000-16        70.7ms ±24%    74.4ms ±18%     ~     (p=0.095 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=1000000-16        1.30s ±85%     0.79s ±28%     ~     (p=0.841 n=5+5)
WideTableIgnoreColumns/Cockroach-16                          8.48ms ± 1%    8.36ms ± 1%   -1.38%  (p=0.008 n=5+5)
PgbenchQuery/Cockroach-16                                    1.72ms ± 1%    1.74ms ± 1%   +1.14%  (p=0.032 n=5+5)
PgbenchQueryParallel/Cockroach-16                            2.61ms ± 2%    2.63ms ± 5%     ~     (p=0.548 n=5+5)
PgbenchExec/Cockroach-16                                     2.21ms ± 6%    2.12ms ±11%     ~     (p=0.190 n=4+5)

name                                                       old alloc/op   new alloc/op   delta
Select1/Cockroach-16                                         6.25kB ± 1%    6.36kB ± 2%   +1.85%  (p=0.008 n=5+5)
Select2/Cockroach-16                                          108kB ± 0%     110kB ± 0%   +1.13%  (p=0.008 n=5+5)
Select3/Cockroach-16                                          122kB ± 1%     123kB ± 0%   +1.31%  (p=0.008 n=5+5)
Count/Cockroach-16                                           10.4MB ± 0%    10.4MB ± 0%     ~     (p=0.548 n=5+5)
Sort/Cockroach-16                                            38.1MB ± 0%    38.4MB ± 2%   +0.86%  (p=0.032 n=4+5)
SQL/Cockroach/Delete/count=1-16                              52.4kB ± 1%    53.4kB ± 1%   +1.75%  (p=0.008 n=5+5)
SQL/Cockroach/Delete/count=10-16                              120kB ± 2%     120kB ± 1%     ~     (p=0.310 n=5+5)
SQL/Cockroach/Delete/count=100-16                             746kB ± 1%     751kB ± 1%     ~     (p=0.310 n=5+5)
SQL/Cockroach/Delete/count=1000-16                           7.03MB ± 1%    7.13MB ± 7%     ~     (p=0.841 n=5+5)
SQL/Cockroach/Insert/count=1-16                              40.1kB ± 4%    39.7kB ± 2%     ~     (p=0.841 n=5+5)
SQL/Cockroach/Insert/count=10-16                             97.0kB ±13%    98.4kB ±21%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Insert/count=100-16                             589kB ± 2%     600kB ± 4%     ~     (p=0.421 n=5+5)
SQL/Cockroach/Insert/count=1000-16                           5.81MB ± 3%    5.61MB ± 2%     ~     (p=0.056 n=5+5)
SQL/Cockroach/InsertDistinct/count=1-16                       390kB ± 1%     406kB ± 9%     ~     (p=0.056 n=5+5)
SQL/Cockroach/InsertDistinct/count=10-16                      373kB ± 0%     375kB ± 1%     ~     (p=0.151 n=5+5)
SQL/Cockroach/InsertDistinct/count=100-16                     504kB ± 2%     495kB ± 8%     ~     (p=0.841 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=1-16                     54.7kB ± 1%    56.5kB ± 8%     ~     (p=0.151 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=5-16                      125kB ±11%     124kB ± 3%     ~     (p=0.841 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=10-16                     221kB ±14%     262kB ±21%     ~     (p=0.421 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=1-16                     252kB ±19%     247kB ± 8%     ~     (p=0.841 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=5-16                    1.04MB ±46%    0.97MB ±36%     ~     (p=0.548 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=10-16                   1.40MB ± 3%    1.55MB ±15%     ~     (p=0.151 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=1-16                   2.24MB ±26%    1.93MB ±13%     ~     (p=1.000 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=5-16                   8.87MB ±23%   10.15MB ±68%     ~     (p=0.690 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=10-16                  13.9MB ± 0%    13.9MB ± 1%     ~     (p=0.286 n=5+4)
SQL/Cockroach/InsertFK/count=1000/nFks=1-16                  27.7MB ±46%    19.5MB ± 4%     ~     (p=0.190 n=5+4)
SQL/Cockroach/InsertFK/count=1000/nFks=5-16                   129MB ±45%     141MB ±61%     ~     (p=0.690 n=5+5)
SQL/Cockroach/InsertFK/count=1000/nFks=10-16                  167MB ± 1%     188MB ±22%     ~     (p=0.421 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=1-16                 105kB ± 0%     105kB ± 1%     ~     (p=0.905 n=5+4)
SQL/Cockroach/InsertSecondaryIndex/count=10-16                588kB ± 0%     591kB ± 2%     ~     (p=0.841 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=100-16              6.42MB ± 3%    6.41MB ± 1%     ~     (p=0.421 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=1000-16             77.8MB ± 0%    78.2MB ± 0%     ~     (p=0.063 n=4+5)
SQL/Cockroach/InterleavedSelect/count=1-16                   52.4kB ± 1%    56.6kB ±16%     ~     (p=0.063 n=4+5)
SQL/Cockroach/InterleavedSelect/count=10-16                  61.6kB ±20%    61.3kB ±13%     ~     (p=0.421 n=5+5)
SQL/Cockroach/InterleavedSelect/count=100-16                 97.6kB ±18%   101.5kB ±14%     ~     (p=0.310 n=5+5)
SQL/Cockroach/InterleavedSelect/count=1000-16                 563kB ±91%     619kB ±27%     ~     (p=0.222 n=5+5)
SQL/Cockroach/TrackChoices/count=1-16                        65.1kB ±29%    79.2kB ±30%     ~     (p=0.310 n=5+5)
SQL/Cockroach/TrackChoices/count=10-16                       21.1kB ± 0%    24.6kB ±30%     ~     (p=0.111 n=4+5)
SQL/Cockroach/TrackChoices/count=100-16                      18.4kB ±13%    18.9kB ±10%     ~     (p=0.548 n=5+5)
SQL/Cockroach/TrackChoices/count=1000-16                     19.8kB ± 2%    19.8kB ± 1%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Update/count=1-16                              56.7kB ± 1%    57.1kB ± 1%     ~     (p=0.421 n=5+5)
SQL/Cockroach/Update/count=10-16                              125kB ± 0%     126kB ± 1%     ~     (p=0.063 n=5+4)
SQL/Cockroach/Update/count=100-16                             780kB ± 0%     780kB ± 0%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Update/count=1000-16                           6.97MB ± 0%    6.97MB ± 0%     ~     (p=0.905 n=5+4)
SQL/Cockroach/Upsert/count=1-16                               124kB ± 1%     125kB ± 1%     ~     (p=0.310 n=5+5)
SQL/Cockroach/Upsert/count=10-16                              176kB ± 5%     177kB ± 1%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Upsert/count=100-16                             808kB ± 1%     808kB ± 1%     ~     (p=0.690 n=5+5)
SQL/Cockroach/Upsert/count=1000-16                           7.23MB ± 1%    7.44MB ±11%     ~     (p=0.841 n=5+5)
Scan/Cockroach/count=1/limit=0-16                            30.8kB ± 1%    31.0kB ± 1%     ~     (p=0.421 n=5+5)
Scan/Cockroach/count=1/limit=1-16                            31.1kB ± 1%    31.2kB ± 1%     ~     (p=0.690 n=5+5)
Scan/Cockroach/count=1/limit=10-16                           30.9kB ± 1%    31.1kB ± 1%     ~     (p=0.222 n=5+5)
Scan/Cockroach/count=1/limit=100-16                          31.3kB ± 6%    31.5kB ± 6%     ~     (p=0.548 n=5+5)
Scan/Cockroach/count=10/limit=0-16                           31.6kB ± 1%    31.7kB ± 1%     ~     (p=0.690 n=5+5)
Scan/Cockroach/count=10/limit=1-16                           39.8kB ± 1%    40.4kB ± 1%   +1.51%  (p=0.008 n=5+5)
Scan/Cockroach/count=10/limit=10-16                          31.9kB ± 1%    32.0kB ± 1%     ~     (p=0.310 n=5+5)
Scan/Cockroach/count=10/limit=100-16                         32.3kB ± 7%    32.4kB ± 7%     ~     (p=0.690 n=5+5)
Scan/Cockroach/count=100/limit=0-16                          47.2kB ± 1%    47.3kB ± 1%     ~     (p=0.841 n=5+5)
Scan/Cockroach/count=100/limit=1-16                          49.0kB ± 1%    49.1kB ± 1%     ~     (p=0.548 n=5+5)
Scan/Cockroach/count=100/limit=10-16                         49.2kB ± 1%    50.1kB ± 4%     ~     (p=0.056 n=5+5)
Scan/Cockroach/count=100/limit=100-16                        47.4kB ± 1%    47.8kB ± 2%     ~     (p=0.151 n=5+5)
Scan/Cockroach/count=1000/limit=0-16                          202kB ± 1%     203kB ± 1%     ~     (p=0.421 n=5+5)
Scan/Cockroach/count=1000/limit=1-16                          138kB ± 1%     138kB ± 1%     ~     (p=0.841 n=5+5)
Scan/Cockroach/count=1000/limit=10-16                         139kB ± 0%     139kB ± 1%     ~     (p=0.421 n=5+5)
Scan/Cockroach/count=1000/limit=100-16                        150kB ± 0%     152kB ± 3%     ~     (p=0.190 n=4+5)
Scan/Cockroach/count=10000/limit=0-16                        1.73MB ± 1%    1.72MB ± 1%     ~     (p=0.095 n=5+5)
Scan/Cockroach/count=10000/limit=1-16                         138kB ± 0%     138kB ± 1%     ~     (p=0.151 n=5+5)
Scan/Cockroach/count=10000/limit=10-16                        140kB ± 1%     138kB ± 0%   -0.96%  (p=0.016 n=5+4)
Scan/Cockroach/count=10000/limit=100-16                       155kB ± 1%     154kB ± 0%     ~     (p=0.548 n=5+5)
ScanFilter/Cockroach/count1=25/count2=400/limit=1-16         90.1kB ± 1%    90.3kB ± 1%     ~     (p=0.690 n=5+5)
ScanFilter/Cockroach/count1=25/count2=400/limit=10-16        93.7kB ± 1%    93.4kB ± 0%     ~     (p=0.730 n=5+4)
ScanFilter/Cockroach/count1=25/count2=400/limit=50-16         265kB ± 0%     265kB ± 0%     ~     (p=0.343 n=4+4)
OrderBy/Cockroach/count=100000/limit=10/distinct=false-16    26.0MB ± 0%    26.0MB ± 0%     ~     (p=0.690 n=5+5)
OrderBy/Cockroach/count=100000/limit=10/distinct=true-16     65.3MB ± 0%    65.3MB ± 0%     ~     (p=1.000 n=5+4)
WideTable/Cockroach/count=10/bigColumnBytes=10-16             718kB ± 1%     723kB ± 1%     ~     (p=0.095 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=100-16            788kB ± 0%     793kB ± 0%   +0.67%  (p=0.008 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=1000-16          1.44MB ± 0%    1.44MB ± 0%     ~     (p=0.095 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=10000-16         7.68MB ± 0%    7.69MB ± 1%     ~     (p=0.548 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=100000-16        75.8MB ± 0%    76.3MB ± 1%     ~     (p=0.421 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=1000000-16        820MB ± 1%     825MB ± 2%     ~     (p=1.000 n=5+5)
WideTableIgnoreColumns/Cockroach-16                          2.15MB ± 1%    2.15MB ± 0%     ~     (p=0.841 n=5+5)
PgbenchQuery/Cockroach-16                                     305kB ± 1%     306kB ± 0%     ~     (p=0.095 n=5+5)
PgbenchQueryParallel/Cockroach-16                             807kB ± 2%     804kB ± 3%     ~     (p=0.841 n=5+5)
PgbenchExec/Cockroach-16                                      286kB ± 1%     289kB ± 1%     ~     (p=0.111 n=4+5)

name                                                       old allocs/op  new allocs/op  delta
Select1/Cockroach-16                                           83.0 ± 0%      86.0 ± 0%   +3.61%  (p=0.016 n=4+5)
Select2/Cockroach-16                                          1.47k ± 0%     1.49k ± 0%   +1.65%  (p=0.008 n=5+5)
Select3/Cockroach-16                                          1.83k ± 0%     1.86k ± 0%   +1.59%  (p=0.008 n=5+5)
Count/Cockroach-16                                            1.40k ± 6%     1.54k ±33%     ~     (p=0.548 n=5+5)
Sort/Cockroach-16                                              127k ± 0%      127k ± 0%     ~     (p=0.343 n=4+4)
SQL/Cockroach/Delete/count=1-16                                 460 ± 1%       468 ± 0%   +1.69%  (p=0.008 n=5+5)
SQL/Cockroach/Delete/count=10-16                                800 ± 1%       812 ± 2%   +1.58%  (p=0.024 n=5+5)
SQL/Cockroach/Delete/count=100-16                             3.84k ± 0%     4.07k ± 8%     ~     (p=0.286 n=4+5)
SQL/Cockroach/Delete/count=1000-16                            35.9k ±13%     35.3k ± 6%     ~     (p=0.690 n=5+5)
SQL/Cockroach/Insert/count=1-16                                 364 ±30%       347 ±15%     ~     (p=0.952 n=5+5)
SQL/Cockroach/Insert/count=10-16                                684 ±67%       789 ±51%     ~     (p=0.794 n=5+5)
SQL/Cockroach/Insert/count=100-16                             2.71k ± 0%     3.08k ±17%     ~     (p=0.413 n=4+5)
SQL/Cockroach/Insert/count=1000-16                            30.9k ±41%     24.8k ± 4%  -19.61%  (p=0.032 n=5+5)
SQL/Cockroach/InsertDistinct/count=1-16                       2.47k ± 8%     2.57k ± 0%     ~     (p=0.190 n=5+4)
SQL/Cockroach/InsertDistinct/count=10-16                      2.33k ± 1%     2.41k ± 5%     ~     (p=0.095 n=5+5)
SQL/Cockroach/InsertDistinct/count=100-16                     3.61k ±10%     3.47k ±10%     ~     (p=0.690 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=1-16                        447 ± 2%       471 ± 5%   +5.41%  (p=0.024 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=5-16                        976 ±16%       947 ± 6%     ~     (p=0.889 n=5+5)
SQL/Cockroach/InsertFK/count=1/nFks=10-16                     1.63k ±26%     2.12k ±32%     ~     (p=0.421 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=1-16                     1.93k ±29%     1.89k ±11%     ~     (p=0.810 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=5-16                     8.68k ±64%     7.90k ±51%     ~     (p=1.000 n=5+5)
SQL/Cockroach/InsertFK/count=10/nFks=10-16                    10.0k ± 3%     11.9k ±22%     ~     (p=0.222 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=1-16                    18.9k ±47%     15.1k ±17%     ~     (p=0.548 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=5-16                    70.4k ±34%     86.8k ±96%     ~     (p=0.841 n=5+5)
SQL/Cockroach/InsertFK/count=100/nFks=10-16                   95.7k ± 0%    100.7k ±18%     ~     (p=0.841 n=5+5)
SQL/Cockroach/InsertFK/count=1000/nFks=1-16                    243k ±64%      143k ± 5%     ~     (p=0.190 n=5+4)
SQL/Cockroach/InsertFK/count=1000/nFks=5-16                   1.07M ±68%     1.23M ±84%     ~     (p=0.690 n=5+5)
SQL/Cockroach/InsertFK/count=1000/nFks=10-16                  1.06M ± 4%     1.30M ±40%     ~     (p=1.000 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=1-16                   555 ± 0%       560 ± 0%   +0.86%  (p=0.029 n=4+4)
SQL/Cockroach/InsertSecondaryIndex/count=10-16                2.50k ± 0%     2.56k ± 4%     ~     (p=0.381 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=100-16               21.8k ± 6%     22.0k ± 3%     ~     (p=0.690 n=5+5)
SQL/Cockroach/InsertSecondaryIndex/count=1000-16               308k ± 0%      309k ± 0%     ~     (p=0.886 n=4+4)
SQL/Cockroach/InterleavedSelect/count=1-16                      581 ±14%       598 ±18%     ~     (p=0.286 n=5+5)
SQL/Cockroach/InterleavedSelect/count=10-16                     663 ±18%       664 ±15%     ~     (p=0.389 n=5+5)
SQL/Cockroach/InterleavedSelect/count=100-16                  1.15k ±17%     1.18k ±14%     ~     (p=0.548 n=5+5)
SQL/Cockroach/InterleavedSelect/count=1000-16                 7.28k ±80%     7.93k ±27%     ~     (p=0.206 n=5+5)
SQL/Cockroach/TrackChoices/count=1-16                           523 ±40%       680 ±40%     ~     (p=0.079 n=5+5)
SQL/Cockroach/TrackChoices/count=10-16                          117 ± 0%       154 ±51%  +31.97%  (p=0.016 n=4+5)
SQL/Cockroach/TrackChoices/count=100-16                        92.4 ±23%      95.2 ±20%     ~     (p=1.000 n=5+5)
SQL/Cockroach/TrackChoices/count=1000-16                       84.0 ± 6%      82.8 ± 5%     ~     (p=1.000 n=5+5)
SQL/Cockroach/Update/count=1-16                                 530 ± 1%       539 ± 0%   +1.61%  (p=0.016 n=5+4)
SQL/Cockroach/Update/count=10-16                                897 ± 0%       926 ± 6%   +3.23%  (p=0.008 n=5+5)
SQL/Cockroach/Update/count=100-16                             4.27k ± 0%     4.28k ± 1%   +0.34%  (p=0.016 n=4+5)
SQL/Cockroach/Update/count=1000-16                            36.3k ± 0%     36.3k ± 0%     ~     (p=0.730 n=5+4)
SQL/Cockroach/Upsert/count=1-16                               1.09k ± 1%     1.11k ± 0%   +1.48%  (p=0.032 n=5+4)
SQL/Cockroach/Upsert/count=10-16                              1.63k ± 7%     1.65k ± 0%     ~     (p=0.206 n=5+5)
SQL/Cockroach/Upsert/count=100-16                             6.86k ± 0%     6.87k ± 0%     ~     (p=0.524 n=5+4)
SQL/Cockroach/Upsert/count=1000-16                            61.1k ± 1%     65.0k ±12%     ~     (p=0.548 n=5+5)
Scan/Cockroach/count=1/limit=0-16                               325 ± 0%       330 ± 0%   +1.54%  (p=0.029 n=4+4)
Scan/Cockroach/count=1/limit=1-16                               336 ± 1%       340 ± 0%   +1.19%  (p=0.016 n=5+4)
Scan/Cockroach/count=1/limit=10-16                              335 ± 0%       340 ± 1%   +1.73%  (p=0.008 n=5+5)
Scan/Cockroach/count=1/limit=100-16                             337 ± 1%       342 ± 1%   +1.49%  (p=0.048 n=5+5)
Scan/Cockroach/count=10/limit=0-16                              343 ± 0%       348 ± 0%   +1.46%  (p=0.016 n=4+5)
Scan/Cockroach/count=10/limit=1-16                              426 ± 0%       431 ± 0%   +1.27%  (p=0.016 n=4+5)
Scan/Cockroach/count=10/limit=10-16                             353 ± 0%       357 ± 0%   +1.25%  (p=0.016 n=4+5)
Scan/Cockroach/count=10/limit=100-16                            354 ± 1%       359 ± 1%     ~     (p=0.095 n=5+5)
Scan/Cockroach/count=100/limit=0-16                             536 ± 0%       541 ± 0%   +0.97%  (p=0.008 n=5+5)
Scan/Cockroach/count=100/limit=1-16                             426 ± 0%       431 ± 0%   +1.17%  (p=0.029 n=4+4)
Scan/Cockroach/count=100/limit=10-16                            444 ± 0%       451 ± 1%   +1.58%  (p=0.008 n=5+5)
Scan/Cockroach/count=100/limit=100-16                           546 ± 0%       551 ± 0%   +0.92%  (p=0.016 n=4+5)
Scan/Cockroach/count=1000/limit=0-16                          2.45k ± 0%     2.46k ± 0%     ~     (p=0.079 n=5+5)
Scan/Cockroach/count=1000/limit=1-16                            427 ± 0%       431 ± 0%   +1.03%  (p=0.008 n=5+5)
Scan/Cockroach/count=1000/limit=10-16                           444 ± 0%       449 ± 0%   +1.13%  (p=0.029 n=4+4)
Scan/Cockroach/count=1000/limit=100-16                          641 ± 2%       647 ± 2%     ~     (p=0.087 n=5+5)
Scan/Cockroach/count=10000/limit=0-16                         21.6k ± 0%     21.6k ± 0%     ~     (p=0.310 n=5+5)
Scan/Cockroach/count=10000/limit=1-16                           428 ± 0%       434 ± 1%   +1.45%  (p=0.008 n=5+5)
Scan/Cockroach/count=10000/limit=10-16                          490 ±22%       449 ± 0%   -8.33%  (p=0.016 n=5+4)
Scan/Cockroach/count=10000/limit=100-16                         680 ± 9%       655 ± 6%     ~     (p=0.683 n=5+5)
ScanFilter/Cockroach/count1=25/count2=400/limit=1-16            879 ± 3%       858 ± 0%     ~     (p=0.746 n=5+4)
ScanFilter/Cockroach/count1=25/count2=400/limit=10-16           919 ± 4%       904 ± 0%     ~     (p=0.619 n=5+4)
ScanFilter/Cockroach/count1=25/count2=400/limit=50-16         2.22k ± 0%     2.23k ± 0%   +0.37%  (p=0.029 n=4+4)
OrderBy/Cockroach/count=100000/limit=10/distinct=false-16     18.9k ± 0%     18.9k ± 0%     ~     (p=0.421 n=5+5)
OrderBy/Cockroach/count=100000/limit=10/distinct=true-16       153k ± 0%      153k ± 0%     ~     (p=0.190 n=5+4)
WideTable/Cockroach/count=10/bigColumnBytes=10-16             5.20k ± 0%     5.27k ± 2%   +1.38%  (p=0.008 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=100-16            5.27k ± 1%     5.31k ± 0%   +0.65%  (p=0.032 n=5+4)
WideTable/Cockroach/count=10/bigColumnBytes=1000-16           5.43k ± 1%     5.55k ± 2%     ~     (p=0.087 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=10000-16          6.25k ± 2%     6.33k ± 5%     ~     (p=0.841 n=5+5)
WideTable/Cockroach/count=10/bigColumnBytes=100000-16         9.37k ±15%     8.76k ± 2%     ~     (p=0.063 n=5+4)
WideTable/Cockroach/count=10/bigColumnBytes=1000000-16        32.5k ±76%     23.4k ±17%     ~     (p=0.421 n=5+5)
WideTableIgnoreColumns/Cockroach-16                           1.15k ± 1%     1.16k ± 0%     ~     (p=0.400 n=4+4)
PgbenchQuery/Cockroach-16                                     2.67k ± 0%     2.73k ± 1%   +2.32%  (p=0.016 n=4+5)
PgbenchQueryParallel/Cockroach-16                             7.00k ± 5%     6.95k ± 3%     ~     (p=1.000 n=5+5)
PgbenchExec/Cockroach-16                                      2.48k ± 1%     2.55k ± 1%   +2.99%  (p=0.016 n=4+5)

@knz knz changed the title WIP - DNM sql, *: make CockroachDB understand schema names Feb 16, 2018

rytaft added a commit to rytaft/cockroach that referenced this pull request Feb 21, 2018

opt: fix name resolution in the optbuilder
This commit uses the new name resolution code from cockroachdb#22753
to properly resolve names in the optbuilder.

Release note: None

rytaft added a commit to rytaft/cockroach that referenced this pull request Feb 21, 2018

opt: fix name resolution in the optbuilder
This commit uses the new name resolution code from cockroachdb#22753
to properly resolve names in the optbuilder.

Release note: None

rytaft added a commit to rytaft/cockroach that referenced this pull request Feb 22, 2018

opt: fix name resolution in the optbuilder
This commit uses the new name resolution code from cockroachdb#22753
to properly resolve names in the optbuilder.

Release note: None

rytaft added a commit to rytaft/cockroach that referenced this pull request Feb 22, 2018

opt: fix name resolution in the optbuilder
This commit uses the new name resolution code from cockroachdb#22753
to properly resolve names in the optbuilder.

Release note: None

rytaft added a commit to rytaft/cockroach that referenced this pull request Feb 22, 2018

opt: fix name resolution in the optbuilder
This commit uses the new name resolution code from cockroachdb#22753
to properly resolve names in the optbuilder.

Release note: None

rytaft added a commit to rytaft/cockroach that referenced this pull request Feb 22, 2018

opt: fix name resolution in the optbuilder
This commit uses the new name resolution code from cockroachdb#22753
to properly resolve names in the optbuilder.

Release note: None

@knz knz deleted the knz:20180202-schema-proto branch Apr 27, 2018

nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this pull request Apr 30, 2018

sql: fix information_schema.constraint_column_usage.constraint_schema
Found while working on cockroachdb#22298.

This column was missed in cockroachdb#22753. It was displaying the constraint's
database instead of the constraint's schema.

Release note (bug fix): The constraint_schema column in
information_schema.constraint_column_usage now displays the
constraint's schema instead of its catalog.

nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this pull request Apr 30, 2018

sql: fix information_schema.constraint_column_usage.constraint_schema
Found while working on cockroachdb#22298.

This column was missed in cockroachdb#22753. It was displaying each constraint's
database instead of each constraint's schema.

Release note (bug fix): The constraint_schema column in
information_schema.constraint_column_usage now displays the
constraint's schema instead of its catalog.

nvanbenschoten added a commit to nvanbenschoten/cockroach that referenced this pull request May 1, 2018

sql: fix information_schema.constraint_column_usage.constraint_schema
Found while working on cockroachdb#22298.

This column was missed in cockroachdb#22753. It was displaying each constraint's
database instead of each constraint's schema.

Release note (bug fix): The constraint_schema column in
information_schema.constraint_column_usage now displays the
constraint's schema instead of its catalog.

craig bot pushed a commit that referenced this pull request May 1, 2018

Merge #25099 #25158 #25190
25099: sql: add "public" pseudo-role. r=mberhault a=mberhault

Fixes #23818

The "public" role is special in the sense that:
* it does not have an entry in the system table
* all users are implicit members (but not listed)
* it can have privileges assigned to it

It has SELECT privileges on virtual tables.

The errors returned when attempting to do illegal things with "public"
are odd, but follow postgres behavior:
* creating "public": "public is reserved"
* dropping "public": "cannot use special role specifier"
* change role memberships (as member or as role): "role does not exist"

The last one is odd and due to the fact that the role technically does
not exist but is reserved. I would prefer to spit out a "reserved role
public cannot be a member of another role".

We also add a migration to ensure that there is no user or role named
"public" in system.users. If there is, we fail and tell the user to drop
it and try again.

Release note (sql change): add "public" pseudo-role.

25158: sql: fail gracefully on unsupported multi-arg aggregations r=knz a=knz

Fixes #23798.

CockroachDB does not yet support running aggregation functions with
more than one argument (#10495).

Prior to this patch, an error was properly generated for the situation
where an aggregate function is applied to multiple arguments in
"simple" contexts; however the check was absent when used in a window
frame, and attempting to use multiple arguments in that context would
cause a panic.

Intuitively, this code path should not have been reachable because
issue #10495 would otherwise suggest that no aggregate function
accepting more than one argument should even be defined.

Unfortunately, a previous change meant to experiment with distributed
execution of multi-argument aggregates introduced the definitions of
two such aggregates: `final_variance()` and `final_stddev()`.
This in turns enabled the code path leading to a crash.

To remove access to this code path required removing access to these
particular built-in functions from the SQL dialect. This patch
achieves this by introducing a boolean flag `Private` on built-in
functions, set to true for these two, which prevent both use by SQL
queries and auto-generation of docs.

Release note (bug fix): CockroachDB now properly reports an error when
using the internal-only functions `final_variance()` and
`final_stddev()` instead of causing a crash.

25190: sql: fix information_schema.constraint_column_usage.constraint_schema r=nvanbenschoten a=nvanbenschoten

Found while working on #22298.

This column was missed in #22753. It was displaying each constraint's
database instead of each constraint's schema.

Release note (bug fix): The constraint_schema column in
information_schema.constraint_column_usage now displays the
constraint's schema instead of its catalog.

Co-authored-by: marc <marc@cockroachlabs.com>
Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>

craig bot pushed a commit that referenced this pull request May 1, 2018

Merge #25100 #25158 #25190 #25215
25100: sql: introduce SessionData.Copy r=andreimatei a=andreimatei

Make the SessionData struct copiable. This will be used to copy state
from a session to internal statements that need to be run in the same
context (particularly, with the same user and database).

This patch removes a mutex protecting sessionData.AppName. It used to be
that the field was accessed concurrently by connEx.Serialize() - a
method used by the "session registry". This patch creates an atomic that
parallels sessionData.AppName for that purpose.

Release note: None

25158: sql: fail gracefully on unsupported multi-arg aggregations r=knz a=knz

Fixes #23798.

CockroachDB does not yet support running aggregation functions with
more than one argument (#10495).

Prior to this patch, an error was properly generated for the situation
where an aggregate function is applied to multiple arguments in
"simple" contexts; however the check was absent when used in a window
frame, and attempting to use multiple arguments in that context would
cause a panic.

Intuitively, this code path should not have been reachable because
issue #10495 would otherwise suggest that no aggregate function
accepting more than one argument should even be defined.

Unfortunately, a previous change meant to experiment with distributed
execution of multi-argument aggregates introduced the definitions of
two such aggregates: `final_variance()` and `final_stddev()`.
This in turns enabled the code path leading to a crash.

To remove access to this code path required removing access to these
particular built-in functions from the SQL dialect. This patch
achieves this by introducing a boolean flag `Private` on built-in
functions, set to true for these two, which prevent both use by SQL
queries and auto-generation of docs.

Release note (bug fix): CockroachDB now properly reports an error when
using the internal-only functions `final_variance()` and
`final_stddev()` instead of causing a crash.

25190: sql: fix information_schema.constraint_column_usage.constraint_schema r=nvanbenschoten a=nvanbenschoten

Found while working on #22298.

This column was missed in #22753. It was displaying each constraint's
database instead of each constraint's schema.

Release note (bug fix): The constraint_schema column in
information_schema.constraint_column_usage now displays the
constraint's schema instead of its catalog.

25215: build: make make ignore go files in testdata directories r=knz a=knz

Otherwise the special file in pkg/cmd/prereqs/testdata will break.

Ideally we'll want to use the 'prereqs' tool instead. For now this will do.

Release note: none

Co-authored-by: Andrei Matei <andrei@cockroachlabs.com>
Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>
Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>

craig bot pushed a commit that referenced this pull request May 1, 2018

Merge #25190 #25215
25190: sql: fix information_schema.constraint_column_usage.constraint_schema r=nvanbenschoten a=nvanbenschoten

Found while working on #22298.

This column was missed in #22753. It was displaying each constraint's
database instead of each constraint's schema.

Release note (bug fix): The constraint_schema column in
information_schema.constraint_column_usage now displays the
constraint's schema instead of its catalog.

25215: build: make make ignore go files in testdata directories r=knz a=knz

Otherwise the special file in pkg/cmd/prereqs/testdata will break.

Ideally we'll want to use the 'prereqs' tool instead. For now this will do.

Release note: none

Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>
Co-authored-by: Raphael 'kena' Poss <knz@cockroachlabs.com>

craig bot pushed a commit that referenced this pull request May 2, 2018

Merge #25220
25220: backport-2.0: sql: fix information_schema.constraint_column_usage.constraint_schema r=nvanbenschoten a=nvanbenschoten

Backport 1/1 commits from #25190.

/cc @cockroachdb/release

---

Found while working on #22298.

This column was missed in #22753. It was displaying each constraint's
database instead of each constraint's schema.

Release note (bug fix): The constraint_schema column in
information_schema.constraint_column_usage now displays the
constraint's schema instead of its catalog.


Co-authored-by: Nathan VanBenschoten <nvanbenschoten@gmail.com>

andreimatei added a commit to andreimatei/cockroach that referenced this pull request Sep 26, 2018

sql: fix race in TxnAborter
TxnAborter was being used by several tests to modify server test knobs
after the server had started. That was racy; one can't simply change a
knob from under a running server.
The race was introduced in cockroachdb#22753 which needed to defer the activation
of the StatementFilter knob. Luckily, since then, the reason for that
deferment has gone away: the reason used to be that, if a
StatementFilter was installed, we enabled a check in the executor that
planning doesn't change the AST. The PR in question was making the
planner change the AST by qualifying tables with the public schema.
In the executor rewrite, we got rid of that check altogether, so this
patch restores the TxnAborter to setting up its knobs before the server
starts.

Release note: None

andreimatei added a commit to andreimatei/cockroach that referenced this pull request Sep 26, 2018

sql: fix race in TxnAborter
TxnAborter was being used by several tests to modify server test knobs
after the server had started. That was racy; one can't simply change a
knob from under a running server.
The race was introduced in cockroachdb#22753 which needed to defer the activation
of the StatementFilter knob. Luckily, since then, the reason for that
deferment has gone away: the reason used to be that, if a
StatementFilter was installed, we enabled a check in the executor that
planning doesn't change the AST. The PR in question was making the
planner change the AST by qualifying tables with the public schema.
In the executor rewrite, we got rid of that check altogether, so this
patch restores the TxnAborter to setting up its knobs before the server
starts.

Fixes cockroachdb#29028

Release note: None

andreimatei added a commit to andreimatei/cockroach that referenced this pull request Sep 26, 2018

sql: fix race in TxnAborter
TxnAborter was being used by several tests to modify server test knobs
after the server had started. That was racy; one can't simply change a
knob from under a running server.
The race was introduced in cockroachdb#22753 which needed to defer the activation
of the StatementFilter knob. Luckily, since then, the reason for that
deferment has gone away: the reason used to be that, if a
StatementFilter was installed, we enabled a check in the executor that
planning doesn't change the AST. The PR in question was making the
planner change the AST by qualifying tables with the public schema.
In the executor rewrite, we got rid of that check altogether, so this
patch restores the TxnAborter to setting up its knobs before the server
starts.

Fixes cockroachdb#29028

Release note: None

craig bot pushed a commit that referenced this pull request Sep 26, 2018

Merge #30670
30670: sql: fix race in TxnAborter r=andreimatei a=andreimatei

TxnAborter was being used by several tests to modify server test knobs
after the server had started. That was racy; one can't simply change a
knob from under a running server.
The race was introduced in #22753 which needed to defer the activation
of the StatementFilter knob. Luckily, since then, the reason for that
deferment has gone away: the reason used to be that, if a
StatementFilter was installed, we enabled a check in the executor that
planning doesn't change the AST. The PR in question was making the
planner change the AST by qualifying tables with the public schema.
In the executor rewrite, we got rid of that check altogether, so this
patch restores the TxnAborter to setting up its knobs before the server
starts.

Fixes #29028

Release note: None

Co-authored-by: Andrei Matei <andrei@cockroachlabs.com>

craig bot pushed a commit that referenced this pull request Sep 26, 2018

Merge #30670
30670: sql: fix race in TxnAborter r=andreimatei a=andreimatei

TxnAborter was being used by several tests to modify server test knobs
after the server had started. That was racy; one can't simply change a
knob from under a running server.
The race was introduced in #22753 which needed to defer the activation
of the StatementFilter knob. Luckily, since then, the reason for that
deferment has gone away: the reason used to be that, if a
StatementFilter was installed, we enabled a check in the executor that
planning doesn't change the AST. The PR in question was making the
planner change the AST by qualifying tables with the public schema.
In the executor rewrite, we got rid of that check altogether, so this
patch restores the TxnAborter to setting up its knobs before the server
starts.

Fixes #29028

Release note: None

Co-authored-by: Andrei Matei <andrei@cockroachlabs.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.