cockroach icon indicating copy to clipboard operation
cockroach copied to clipboard

sql: Complete the information_schema by adding empty table definitions

Open nvb opened this issue 10 years ago • 20 comments

https://github.com/cockroachdb/cockroach/pull/8119 introduced the framework for creating virtual schemas, and specifically, the information_schema. Subsequently, a group PRs added what was deemed to be the most immediately critical set of tables. However, the specification for the information_schema is extensive, and there are a number of other tables which can be added with relative ease. The set of all information_schema tables is:

  • [x] character_sets
  • [x] collations
  • [x] collation_character_set_applicability
  • [x] columns
  • [x] column_privileges
  • [x] constraint_column_usage
  • [ ] engines
  • [ ] events
  • [ ] files
  • [ ] global_status
  • [ ] session_statuss
  • [ ] global_variables
  • [ ] session_variables
  • [x] key_column_usage
  • [ ] optimizer_trace
  • [x] parameters
  • [ ] partitions
  • [ ] plugins
  • [ ] processlist
  • [ ] profiling
  • [x] referential_constraints
  • [x] routines
  • [x] schemata
  • [x] schema_privileges
  • [x] sequences
  • [x] statistics
  • [x] tables
  • [ ] tablespaces
  • [x] table_constraints
  • [x] table_privileges
  • [ ] triggers
  • [x] user_privileges
  • [x] views

The process for adding a new information_schema table is:

  1. create a new virtualSchemaTable variable with a table schema definition
  2. construct a population function implementation to populate this schema on demand
  3. add the variable to the information_schema's table list
  4. add necessary testing to testdata/information_schema

Helpful sources:

nvb avatar Aug 18 '16 21:08 nvb

@nvanbenschoten I'm going to create the information_schema.statistics as follow, what do you think?

CREATE TABLE information_schema.statistics (
    TABLE_CATALOG STRING NOT NULL DEFAULT '',
    TABLE_SCHEMA STRING NOT NULL DEFAULT '',
    TABLE_NAME STRING NOT NULL DEFAULT '',
    NON_UNIQUE BOOL NOT NULL DEFAULT FALSE,
    INDEX_SCHEMA STRING NOT NULL DEFAULT '',
    INDEX_NAME STRING NOT NULL DEFAULT '',
    SEQ_IN_INDEX INT NOT NULL DEFAULT 0,
    COLUMN_NAME STRING NOT NULL DEFAULT '',
    "COLLATION" STRING NOT NULL DEFAULT '',
    CARDINALITY INT NOT NULL DEFAULT 0,
    DIRECTION STRING NOT NULL DEFAULT '',
    STORING BOOL NOT NULL DEFAULT FALSE 
);

yznming avatar Oct 25 '16 10:10 yznming

That sounds reasonable @yananzhi, thanks!

nvb avatar Oct 25 '16 14:10 nvb

@nvanbenschoten I'm planning to create information_schema.views as follows :

CREATE TABLE information_schema.views (
    TABLE_CATALOG STRING NOT NULL DEFAULT '',
    TABLE_SCHEMA STRING NOT NULL DEFAULT '',
    TABLE_NAME STRING NOT NULL DEFAULT '',
    VIEW_DEFINITION STRING NOT NULL DEFAULT '',
    CHECK_OPTION STRING NOT NULL DEFAULT '',
    IS_UPDATABLE BOOL NOT NULL DEFAULT FALSE,
    IS_INSERTABLE_INTO BOOL NOT NULL DEFAULT FALSE,
    IS_TRIGGER_UPDATABLE BOOL NOT NULL DEFAULT FALSE,
    IS_TRIGGER_DELETABLE BOOL NOT NULL DEFAULT FALSE,
    IS_TRIGGER_INSERTABLE_INTO BOOL NOT NULL DEFAULT FALSE
);

It refers to the postgresql document: https://www.postgresql.org/docs/9.5/static/infoschema-views.html Look forward to your advice. Thanks.

szpony avatar Oct 27 '16 13:10 szpony

@mtMabo yep that looks good. Thanks!

nvb avatar Oct 27 '16 17:10 nvb

@nvanbenschoten I'm planning to create information_schema.user_privileges as follows :

CREATE  TABLE information_schema .user_privileges (
   GRANTEE STRING  NOT NULL DEFAULT '',
   TABLE_CATALOG  STRING NOT  NULL  DEFAULT '',
   PRIVILEGE_TYPE  STRING NOT NULL DEFAULT '',
   IS_GRANTABLE  BOOL NOT NULL DEFAULT FALSE
);

It refers to the mysql document: https://dev.mysql.com/doc/refman/5.7/en/user-privileges-table.html Look forward to your advice. Thanks.

yangliang9004 avatar May 04 '17 06:05 yangliang9004

@yangliang9004, LGTM

jordanlewis avatar May 04 '17 15:05 jordanlewis

@benesch https://github.com/radutopala/cockroach-app/issues .. found these so far, with PHP/Symfony/Doctrine.

radutopala avatar May 14 '17 08:05 radutopala

@nvanbenschoten I wanted to pick up column_privileges, like this

CREATE TABLE information_schema.column_privilege (
	GRANTER STRING NOT NULL DEFAULT '',
	GRANTEE STRING NOT NULL DEFAULT '',
	TABLE_CATALOG STRING NOT NULL DEFAULT '',
	TABLE_SCHEMA STRING NOT NULL DEFAULT '',
	TABLE_NAME STRING NOT NULL DEFAULT '',
	COLUMN_NAME STRING NOT NULL DEFAULT '',
	PRIVILEGE_TYPE STRING NOT NULL DEFAULT '',
	IS_GRANTABLE BOOL NOT NULL DEFAULT FALSE
);

But the column_descriptor in ColumnDescriptor doesnot have any PriviliegeDescriptor.

Any pointers for me ?

sum12 avatar Dec 22 '17 16:12 sum12

CockroachDB doesn't have separate column privileges like some other databases do. Postgres before 8.4 had the same limitation, so I'd follow their old behavior here:

In PostgreSQL, you can only grant privileges on entire tables, not individual columns. Therefore, this view contains the same information as table_privileges, just represented through one row for each column in each appropriate table, but it only covers privilege types where column granularity is possible: SELECT, INSERT, UPDATE, REFERENCES.

— https://www.postgresql.org/docs/8.3/static/infoschema-column-privileges.html

On Fri, Dec 22, 2017 at 11:32 AM, Sumit [email protected] wrote:

@nvanbenschoten https://github.com/nvanbenschoten I wanted to pick up column_privileges, like this

CREATE TABLE information_schema.column_privilege ( GRANTER STRING NOT NULL DEFAULT '', GRANTEE STRING NOT NULL DEFAULT '', TABLE_CATALOG STRING NOT NULL DEFAULT '', TABLE_SCHEMA STRING NOT NULL DEFAULT '', TABLE_NAME STRING NOT NULL DEFAULT '', COLUMN_NAME STRING NOT NULL DEFAULT '', PRIVILEGE_TYPE STRING NOT NULL DEFAULT '', IS_GRANTABLE BOOL NOT NULL DEFAULT FALSE );

But the column_descriptor in ColumnDescriptor https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/sqlbase/structured.pb.go#L447 doesnot have any PriviliegeDescriptor https://github.com/cockroachdb/cockroach/blob/master/pkg/sql/sqlbase/privilege.pb.go#L31 .

Any pointers for me ?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cockroachdb/cockroach/issues/8675#issuecomment-353632118, or mute the thread https://github.com/notifications/unsubscribe-auth/AA15IM4i4ncCbv7Y2znmj1V0J3rmEY6pks5tC9mbgaJpZM4Jn6VP .

benesch avatar Dec 22 '17 16:12 benesch

@sum12 thanks for the interest! @benesch is exactly right that we should handle this the same way Postgres did before they added column level privileges. Let me know if you plan to pick this up or if you have any other questions.

nvb avatar Dec 23 '17 02:12 nvb

I would like to add character_sets table, based on the schema for Postgres. Do I understand correctly, that there is just one default collation for CockroachDB and it's not stored per database? Does that mean that in this table DEFAULT_COLLATE_CATALOG and DEFAULT_COLLATE_SCHEMA will always be NULL, while DEFAULT_COLLATE_NAME will be "default"?

mknycha avatar Oct 29 '20 13:10 mknycha

@nvanbenschoten ⬆️

mknycha avatar Oct 30 '20 13:10 mknycha

@mknycha thanks for the interest in contributing! I'm a little removed from this area right now so I don't know the exact details of how we would like to populate the character_sets table. @rafiss do you have any thoughts here?

nvb avatar Nov 11 '20 02:11 nvb

Hmm I'm not sure what we want here. Right now, we actually use en-US as the "default collation" for all string columns in the pg_attribute table. But I think as per #54989, this may not be correct.

For the purposes of this information_schema.character_sets table, it seems like maybe it is correct to use en_US as the default collation. cc @otan do you know what would be best here?

rafiss avatar Nov 11 '20 18:11 rafiss

i've added the concept of a default collation in https://github.com/cockroachdb/cockroach/pull/56598

otan avatar Nov 12 '20 05:11 otan

Thanks @otan

So @mknycha if you are interested in working on character_sets, then please go ahead. You were correct earlier -- in this table DEFAULT_COLLATE_CATALOG and DEFAULT_COLLATE_SCHEMA will always be NULL, and DEFAULT_COLLATE_NAME will be "default".

rafiss avatar Nov 16 '20 21:11 rafiss

hi, i'd like to work on collations

mneverov avatar Dec 04 '20 16:12 mneverov

@mneverov thanks, we'd be happy to receive your work. it should be pretty similar to pg_collation, which we have defined in pg_catalog.go

rafiss avatar Dec 04 '20 16:12 rafiss

hi, i'd like to add the engine table as following:


+---------+---------+-----------------------------------------------------------+--------------+----+------------+
| ENGINE  | SUPPORT | COMMENT                                                   | TRANSACTIONS | XA | SAVEPOINTS |
+---------+---------+-----------------------------------------------------------+--------------+----+------------+
| RocksDB | YES     | A Persistent Key-Value Store for Flash and RAM Storage    | YES          | NO | YES        |
| Pebble  | DEFAULT | An embedded key-value store with a RocksDB-compatible API | NO           | NO | NO         |
+---------+---------+-----------------------------------------------------------+--------------+----+------------+

I used mysql docs as a reference. Question: both transactions and savepoints in engines are irrelevant as CRDB uses it's own implementation. Should it then be both YES for Pebble?

mneverov avatar Dec 07 '20 16:12 mneverov

hi, i'd like to work on session_variables (variable string not null, value string not null).

mneverov avatar Dec 11 '20 18:12 mneverov