Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our previous strategy of:
pg_views
andpg_matviews
in the correct orderwas incorrect on both counts. Those tables have no specific ordering so
the results can come back in any order. Also, we can have views that
depend on materialized views.
We need to get all of the views - materialized and otherwise - from a
single query and we need them to be ordered in the same order they were
created.
I inspected the definitions of
pg_views
andpg_matviews
and noticedthey are both built from pg_class. Querying on that table gives us a way
to get both the views and materialized views in a single query. Ordering
by 'oid' is the simplest way to order them by insertion order. Dropping
a view that depends on a child view also requires dropping that child
view, so ordering in this manner should be sufficient.
This technically means we don't need the connection decorator I
introduced in the previous change, but we know we will be using that
functionality very soon in another change, so I'm leaving it be for now.
I ran the improved test of
#views
in thepostgres_spec
hundreds oftimes and got a consistent, valid order every time.