这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@nicuveo
Copy link
Contributor

@nicuveo nicuveo commented Mar 26, 2020

Description

This is the frontend part of #91. WARNING: it is an ugly workaround!

The problem is as follows: this query used information_schema to retrieve information about the underlying postgres database. Unfortunately, neither information_schema.tables nor information_schema.columns contain data about materialized views. What this PR does is to change the query to instead rely on postgres internals, such as pg_class and pg_attribute. It has a few upsides; notably, retrieving comments is much easier now, since we have access to the oid of each element, and we can just use col_description and obj_description.

However, the previous version of that query returned every single column of the columns view, unmodified. To emulate that behaviour, I had to recreate the entire columns view in the query, while fixing it so that it includes materialized views.

I obtained the definition of columns by running psql -E and running \dS+ information_schema.columns. The only change is as follows:

before: c.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])
after: c.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'm'::"char"])

Affected components

  • Console

Limitations, known bugs & workarounds

There are several things that are missing from this PR, in its current state:

  • currently, the view_info part of the query is computed using the information_schema.views view, which... suffers from the exact same problem: not listing materialized views. I am not sure whether we actually want to treat them as views as far as the console is concerned, but that's something to check,
  • I have NOT checked that the console properly supports this new MATERIALIZED VIEW table type everywhere; from my limited testing, it treats is as a view (the name is italicized for instance),
  • I have NOT done regression testing beyond some very simple examples on my test database,
  • I have NOT written new tests, nor done extensive tests in the console; I have simply tested, on one materialized view:
    • tracking it
    • untracking it
    • running a query against it in GraphiQL
    • checking that the data is correct (both rows and columns) in the Data tab

Ideally, this would be rewritten to call a backend function, and none of the postgres internals would be in the frontend. But in recent discussions we have agreed that it was preferable to do this workaround before doing the necessary server work.

@nicuveo nicuveo requested a review from beerose as a code owner March 26, 2020 17:26
@hasura-bot

This comment has been minimized.

@rikinsk rikinsk added the c/console Related to console label Mar 27, 2020
@wawhal wawhal requested a review from arvi3411301 March 27, 2020 12:14
@nicuveo
Copy link
Contributor Author

nicuveo commented Mar 27, 2020

An update on this:

I had used the definition of information_schema.columns from postgres 12, which is not backwards compatible. That's why the tests were failing on CircleCI: our tests use postgres 10.

I pushed a new commit that rewrites the query, based on how it was defined in posgres 9.5, which is the oldest version we support. I stripped some of the fields that either had no information (as in: they were declared as cast NULL as ...) or that relied on internal functions that no longer exist in version 12.

Importantly, this is still a WORK IN PROGRESS. I am currently running all cypress tests on versions 12 and 10, and will perform some additional manual ones / will add cypress tests for materialized views.

@hasura-bot

This comment has been minimized.

@nicuveo nicuveo force-pushed the clean-untracked-request branch from f0305c1 to 7e82f37 Compare March 28, 2020 00:12
@hasura-bot

This comment has been minimized.

@nicuveo nicuveo force-pushed the clean-untracked-request branch from 7e82f37 to a9e9b7b Compare March 28, 2020 15:53
@hasura-bot

This comment has been minimized.

@hasura-bot

This comment has been minimized.

@nicuveo nicuveo force-pushed the clean-untracked-request branch from db2d4c9 to f4e917e Compare March 30, 2020 13:35
@nicuveo nicuveo requested a review from a team as a code owner March 30, 2020 13:35
@hasura-bot

This comment has been minimized.

@nicuveo nicuveo force-pushed the clean-untracked-request branch from 9d340a5 to 64af004 Compare March 30, 2020 22:48
@hasura-bot

This comment has been minimized.

@nicuveo nicuveo force-pushed the clean-untracked-request branch from 64af004 to 3230392 Compare March 30, 2020 23:44
@hasura-bot

This comment has been minimized.

@nicuveo nicuveo requested a review from a team as a code owner March 31, 2020 00:30
@hasura-bot
Copy link
Contributor

Review app for commit acb8467 deployed to Heroku: https://hge-ci-pull-4204.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4204-acb8467c

@nicuveo nicuveo force-pushed the clean-untracked-request branch from acb8467 to 490b8a0 Compare March 31, 2020 01:24
@nicuveo nicuveo requested a review from a team as a code owner March 31, 2020 01:24
Antoine Leblanc added 7 commits April 1, 2020 09:03
Instead of sticking to the information_schema tables, this now uses pg internals. This is not a regression, as the query was already relying on some of them. Furthermore, this heavily simplifies the comment subqueries, since we have access to the oid.
This is horribly verbose; but it does the job. The giant expression of `isc` is almost exactly the definition of the `information_schema.columns` view, with one major restriction: it also list columns present in materialized views. This is very ugly and could be simplified heavily.

For technical details: I obtained the details of the view by running `psql -E` and using `\dS+ information_schema.columns`. The only difference is this:

before: `c.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'f'::"char", 'p'::"char"])`
after:  `c.relkind = ANY (ARRAY['r'::"char", 'v'::"char", 'm'::"char"])`
Antoine Leblanc added 3 commits April 1, 2020 09:03
To be more precise: I have used the definition of `information_schema.columns` as it was in [version 9.5](https://github.com/postgres/postgres/blob/REL9_5_STABLE/src/backend/catalog/information_schema.sql), which is the oldest version we support.

I tested it on my local database, which is on version 12. To make sure it worked, I had to remove several functions call that did not exist anymore. The result is a trimmed-down version, that has only the most essential fields. I am going to run more tests to see whether this is enough or not.
@nicuveo nicuveo force-pushed the clean-untracked-request branch from 490b8a0 to 7fb9bdb Compare April 1, 2020 08:03
@hasura-bot
Copy link
Contributor

Review app for commit 7fb9bdb deployed to Heroku: https://hge-ci-pull-4204.herokuapp.com
Docker image for server: hasura/graphql-engine:pull4204-7fb9bdb7

@nicuveo
Copy link
Contributor Author

nicuveo commented Apr 1, 2020

Sorry for the noise on this PR: I was blocked by what turned out to be #4250. I'll close this PR and open a new one when I have something a bit cleaner.

@nicuveo nicuveo closed this Apr 1, 2020
@hasura-bot
Copy link
Contributor

Review app https://hge-ci-pull-4204.herokuapp.com is deleted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c/console Related to console

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants