Re: Questions about PostgreSQL implementation details

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема Re: Questions about PostgreSQL implementation details
Дата
Msg-id c1b004c4-dd6b-4a3e-58ce-858596d02b9a@iki.fi
обсуждение исходный текст
Ответ на Questions about PostgreSQL implementation details  (Julien Delplanque <julien.delplanque@inria.fr>)
Список pgsql-hackers
Hi Julien!

On 09/12/2019 17:35, Julien Delplanque wrote:
> Q1. Are PostgreSQL's meta-description tables (such as pg_class) the "reality" concerning the state of the DB or are
theyjust a virtual representation ?
 

Yes, the catalog tables are the authoritative source. The system uses 
those tables internally to get the information too.

Some of the pg_* relations are just views over other catalog tables, though.

> What I would like to know with this question is: would it be possible to implement DDL queries (e.g. CREATE TABLE,
DROPTABLE, CREATE VIEW, ALTER TABLE, etc.) as DML queries that modify the meta-data stored in meta-description tables?
 
> 
> For example, something like:
> 
> INSERT INTO pg_class [...];
> 
> To create a new table (instead of the CREATE TABLE DDL query).
> 
> Q1.1 If it is possible, is what is done in reality? I have the feeling that it is not the case and that DDL queries
areimplemented in C directly.
 
> 
> Q1.2 If it is possible and not done, what is the reason?

The C code for the DDL commands do some things in addition to modifying 
the catalog tables. Notably for CREATE TABLE, it creates the relation 
file in the data directory, where all the data is stored. It also 
handles locking, invalidating various caches, firing event triggers etc. 
Except for creating relation files, those other things happen just in 
memory, though.

It is not supported, and please don't do it in production, but you could 
try it out. Set "allow_system_table_mods=on", and insert to pg_class, 
pg_attribute, etc. See how well it works. Beware that there are internal 
caches, called "syscaches", in backends over the catalog tables, so if 
you modify them directly, you may need to restart for the changes to 
take effect.

> Q2. Are PostgreSQL's "meta-constraints" (i.e. constraints related to database structure such as "a table can only
havea single primary key") implemented in C code or via data constraints on PostgreSQL's meta-description tables?
 
> 
> I guess, again, they are implemented in C code, but I might be wrong.

In C code.

> Q2.1 If they are not implemented via data constraints on meta-description tables, why ?

I think there are some restrictions that cannot easily be represented as 
constraints. Also, we've never supported constraints on catalog tables, 
so no one's given much thought to what it would look like if we did.

> Q2.2 Is there somewhere in the documentation a list of such "meta-constraints" implemented by PostgreSQL?

Hmm, I don't think there is. Your best bet is to just look at the C 
code, I'm afraid.

- Heikki



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Questions about PostgreSQL implementation details
Следующее
От: Tom Lane
Дата:
Сообщение: Re: verbose cost estimate