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: re-vamp the view dependency analysis #17310

Merged
merged 3 commits into from
Aug 4, 2017

Commits on Aug 3, 2017

  1. sql: implement new crdb_internal virtual tables to inspect descriptors

    The views in pg_catalog and information_schema provide introspection
    over the logical schema (pure SQL view) however when testing/debugging
    it is also important to see the descriptor IDs and also other fields
    of descriptors.
    
    This patch provides help for debugging with the following new virtual
    tables:
    
    - `crdb_internal.table_columns`: detailed column IDs and properties
    - `crdb_internal.table_indexes`: detailed index IDs and index properties
    - `crdb_internal.index_columns`: what columns are indexed and how
    - `crdb_internal.backward_dependencies`: which other descriptors each descriptor depends on
    - `crdb_internal.forward_dependencies`: which other descriptors each descriptor is depended on by
    
    These virtual tables are intended to display the contents of
    descriptors without any data transformation, so as to reveal any error
    in the descriptors, if any.
    
    Debugging/fsck tools can later use these to check schema validity.
    knz committed Aug 3, 2017
    Configuration menu
    Copy the full SHA
    e3af3f3 View commit details
    Browse the repository at this point in the history

Commits on Aug 4, 2017

  1. sql: remove the dependencies column from crdb_internal.create_statements

    ... because it was incomplete (missing FK relationships).
    
    The two new tables `crdb_internal.forward_dependencies` and
    `crdb_internal.backward_dependencies` can be used instead.
    knz committed Aug 4, 2017
    Configuration menu
    Copy the full SHA
    148eeaa View commit details
    Browse the repository at this point in the history
  2. sql: re-vamp the view dependency analysis

    Prior to this patch, view dependency analysis during CREATE VIEW was
    broken because it would only check dependencies after plan
    optimization, i.e. possibly after some dependency were lost. For
    example, with the queries:
    
    ```sql
    CREATE VIEW v AS SELECT k FROM (SELECT k,v FROM kv) -- loses dependency on kv.v
    CREATE VIEW v AS SELECT k,v FROM kv WHERE FALSE -- loses dependency on kv
    ```
    
    This patch addresses the issue as follows:
    
    - the dependencies are now collected during the initial construction
      of the query plan, before any optimization are applied. This way we
      ensure the dependency tracking is complete.
    - a migration is implemented that will fix any view descriptor and
      corresponding dependency information that was populated prior to
      this fix.
    knz committed Aug 4, 2017
    Configuration menu
    Copy the full SHA
    e28811c View commit details
    Browse the repository at this point in the history