Re: Accessing schema data in information schema

Lists: pgsql-hackers
From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Accessing schema data in information schema
Date: 2006-03-22 20:41:46
Message-ID: 200603222141.47272.peter_e@gmx.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

I'm updating the information schema for SQL:2003. I'm having some
difficulties with the "sequences" view. It should look approximately
like this (uninteresting stuff omitted):

CREATE VIEW sequences AS
SELECT CAST(current_database() AS sql_identifier) AS sequence_catalog,
CAST(nc.nspname AS sql_identifier) AS sequence_schema,
CAST(c.relname AS sql_identifier) AS sequence_name,
CAST(null AS cardinal_number) AS maximum_value, -- FIXME
CAST(null AS cardinal_number) AS minimum_value, -- FIXME
CAST(null AS cardinal_number) AS increment, -- FIXME
CAST(null AS character_data) AS cycle_option -- FIXME
FROM pg_namespace nc, pg_class c
WHERE c.relnamespace = nc.oid
AND c.relkind = 's';

How does one get at the missing fields. The only way I know is
selecting from the sequence, but how does one work this into this
query? Somehow it seems that these things should be stored in a real
system catalog.

Ideas (short of using PERFORM in PL/pgSQL)?

--
Peter Eisentraut
http://developer.postgresql.org/~petere/


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Accessing schema data in information schema
Date: 2006-03-22 21:11:54
Message-ID: 19743.1143061914@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> How does one get at the missing fields. The only way I know is
> selecting from the sequence, but how does one work this into this
> query? Somehow it seems that these things should be stored in a real
> system catalog.

Yeah. I've occasionally toyed with the idea that sequences should be
rows in a single catalog instead of independent tables as they are now.
This would make for a much smaller disk footprint (with consequent I/O
savings) and would solve problems like the one you have. Unfortunately
the backward-compatibility issues seem a bit daunting :-(. It's
probably not completely impossible, but how do we preserve the existing
behavior that you can "SELECT * FROM seqname" and get the parameters?

Ideally I'd like
SELECT * FROM seqname; -- gets params of one sequence
SELECT * FROM pg_sequence; -- gets params of all sequences

One possible kluge is to make all the sequences be child tables of a
pg_sequence catalog that exists only to be their inheritance parent.
This seems pretty ugly from a performance point of view though.
Selecting from pg_sequence would be really expensive if you have a lot
of sequences, and there wouldn't be any opportunity for reducing the
disk footprint.

(Thinks a bit...) Maybe it would work for pg_sequence to be a real
catalog with a row per sequence, and we also create a view named after
the sequence that simply selects from pg_sequence with an appropriate
WHERE condition.

Plan C would be to say that we don't need to preserve "SELECT * FROM
seqname", but I'll bet there would be some hollering.

regards, tom lane


From: Hannu Krosing <hannu(at)skype(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Accessing schema data in information schema
Date: 2006-03-22 22:10:54
Message-ID: 1143065455.3868.3.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Ühel kenal päeval, K, 2006-03-22 kell 16:11, kirjutas Tom Lane:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > How does one get at the missing fields. The only way I know is
> > selecting from the sequence, but how does one work this into this
> > query? Somehow it seems that these things should be stored in a real
> > system catalog.
>
> Yeah. I've occasionally toyed with the idea that sequences should be
> rows in a single catalog instead of independent tables as they are now.
> This would make for a much smaller disk footprint (with consequent I/O
> savings) and would solve problems like the one you have.

Would it not make page locking problems much worse with all get_next()'s
competeing to update the same page?

At least unless you reserve one page for each sequence.

-------------
Hannu


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Hannu Krosing <hannu(at)skype(dot)net>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Accessing schema data in information schema
Date: 2006-03-22 22:29:08
Message-ID: 20499.1143066548@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hannu Krosing <hannu(at)skype(dot)net> writes:
> hel kenal peval, K, 2006-03-22 kell 16:11, kirjutas Tom Lane:
>> Yeah. I've occasionally toyed with the idea that sequences should be
>> rows in a single catalog instead of independent tables as they are now.
>> This would make for a much smaller disk footprint (with consequent I/O
>> savings) and would solve problems like the one you have.

> Would it not make page locking problems much worse with all get_next()'s
> competeing to update the same page?

Well, there'd be at most about 80 sequences per page (ballpark estimate
remembering that we'd still want to store a sequence name) and the
reduction in demand for shared buffers might outweigh the increased
contention for any one buffer. I haven't seen any examples where get_next
is the key source of contention anyhow. A last point is that in simple
cases where the contention is all on one sequence, you're going to have
that problem anyway.

> At least unless you reserve one page for each sequence.

Which is exactly what I don't want. But we could imagine padding the
tuples to achieve any particular tuples/page ratio we want, if 80 proves
to be uncomfortably many.

regards, tom lane


From: Hannu Krosing <hannu(at)skype(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Accessing schema data in information schema
Date: 2006-03-22 22:48:43
Message-ID: 1143067724.3868.12.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Ühel kenal päeval, K, 2006-03-22 kell 17:29, kirjutas Tom Lane:
> Hannu Krosing <hannu(at)skype(dot)net> writes:
> > Ühel kenal päeval, K, 2006-03-22 kell 16:11, kirjutas Tom Lane:
> >> Yeah. I've occasionally toyed with the idea that sequences should be
> >> rows in a single catalog instead of independent tables as they are now.
> >> This would make for a much smaller disk footprint (with consequent I/O
> >> savings) and would solve problems like the one you have.
>
> > Would it not make page locking problems much worse with all get_next()'s
> > competeing to update the same page?
>
> Well, there'd be at most about 80 sequences per page (ballpark estimate
> remembering that we'd still want to store a sequence name) and the
> reduction in demand for shared buffers might outweigh the increased
> contention for any one buffer. I haven't seen any examples where get_next
> is the key source of contention anyhow.

Probably true. I can't think of one right now either. And we have
caching to solve these cases.

> A last point is that in simple
> cases where the contention is all on one sequence, you're going to have
> that problem anyway.
>
> > At least unless you reserve one page for each sequence.
>
> Which is exactly what I don't want. But we could imagine padding the
> tuples to achieve any particular tuples/page ratio we want, if 80 proves
> to be uncomfortably many.

I guess we can't easily start locking some subarea of a page, say 256
byte subpage, or just the tuple.

OTOH it may be possible as we don't need to lock page header for
sequences as the tuple is updated in place and will not change in size.

OTOOH, I'm afraid we still need to WAL the whole page, so the savings
will be marginal.

------------
Hannu


From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Hannu Krosing <hannu(at)skype(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Accessing schema data in information schema
Date: 2006-03-22 23:10:08
Message-ID: 20060322231008.GB9815@surnet.cl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Hannu Krosing wrote:

> I guess we can't easily start locking some subarea of a page, say 256
> byte subpage, or just the tuple.

> OTOH it may be possible as we don't need to lock page header for
> sequences as the tuple is updated in place and will not change in size.

Huh, we _can_ lock individual tuples, using LockTuple() (or rather,
heap_lock_tuple). Since the tuple is modified in place, there's no need
to lock the whole page.

> OTOOH, I'm afraid we still need to WAL the whole page, so the savings
> will be marginal.

Huh, why? We can just keep the current WAL logging for sequences, or
something very similar, can't we?

--
Alvaro Herrera http://www.CommandPrompt.com/
The PostgreSQL Company - Command Prompt, Inc.


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
Cc: Hannu Krosing <hannu(at)skype(dot)net>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Accessing schema data in information schema
Date: 2006-03-22 23:48:37
Message-ID: 21155.1143071317@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Alvaro Herrera <alvherre(at)commandprompt(dot)com> writes:
> Hannu Krosing wrote:
>> I guess we can't easily start locking some subarea of a page, say 256
>> byte subpage, or just the tuple.

> Huh, we _can_ lock individual tuples, using LockTuple() (or rather,
> heap_lock_tuple). Since the tuple is modified in place, there's no need
> to lock the whole page.

But heap_lock_tuple is pretty expensive and subject to deadlocks. I
think getting the buffer content lock on the page will still be the
right thing.

>> OTOOH, I'm afraid we still need to WAL the whole page, so the savings
>> will be marginal.

> Huh, why? We can just keep the current WAL logging for sequences, or
> something very similar, can't we?

In the case of the first touch of a sequence page after checkpoint, we'd
need to WAL the whole page image to defend against page breaks during
write. After that though the WAL entries would be *smaller* than they
are now, since there'd be no need to log the entire content of the
changed tuple; we'd know we only need to log the counter advance.

It's hard to say whether this'd be a win, loss, or wash without testing.
It'd probably depend on how many nextval's per checkpoint you want to
assume.

regards, tom lane


From: Darcy Buskermolen <darcy(at)wavefire(dot)com>
To: pgsql-hackers(at)postgresql(dot)org
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Accessing schema data in information schema
Date: 2006-03-23 00:40:57
Message-ID: 200603221640.58233.darcy@wavefire.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Wednesday 22 March 2006 13:11, Tom Lane wrote:
> Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > How does one get at the missing fields. The only way I know is
> > selecting from the sequence, but how does one work this into this
> > query? Somehow it seems that these things should be stored in a real
> > system catalog.
>
> Yeah. I've occasionally toyed with the idea that sequences should be
> rows in a single catalog instead of independent tables as they are now.
> This would make for a much smaller disk footprint (with consequent I/O
> savings) and would solve problems like the one you have. Unfortunately
> the backward-compatibility issues seem a bit daunting :-(. It's
> probably not completely impossible, but how do we preserve the existing
> behavior that you can "SELECT * FROM seqname" and get the parameters?
>
> Ideally I'd like
> SELECT * FROM seqname; -- gets params of one sequence
> SELECT * FROM pg_sequence; -- gets params of all sequences
>
> One possible kluge is to make all the sequences be child tables of a
> pg_sequence catalog that exists only to be their inheritance parent.
> This seems pretty ugly from a performance point of view though.
> Selecting from pg_sequence would be really expensive if you have a lot
> of sequences, and there wouldn't be any opportunity for reducing the
> disk footprint.
>
> (Thinks a bit...) Maybe it would work for pg_sequence to be a real
> catalog with a row per sequence, and we also create a view named after
> the sequence that simply selects from pg_sequence with an appropriate
> WHERE condition.

I'd think that would be a workable solution, with documentation notes that
this will be deprecated in favor of information_schema in an upcoming
release ?

>
> Plan C would be to say that we don't need to preserve "SELECT * FROM
> seqname", but I'll bet there would be some hollering.
?

>
> regards, tom lane
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

--
Darcy Buskermolen
Wavefire Technologies Corp.

http://www.wavefire.com
ph: 250.717.0200
fx: 250.763.1759


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Darcy Buskermolen <darcy(at)wavefire(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org, Peter Eisentraut <peter_e(at)gmx(dot)net>
Subject: Re: Accessing schema data in information schema
Date: 2006-03-23 02:38:40
Message-ID: 27257.1143081520@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Darcy Buskermolen <darcy(at)wavefire(dot)com> writes:
> On Wednesday 22 March 2006 13:11, Tom Lane wrote:
>> (Thinks a bit...) Maybe it would work for pg_sequence to be a real
>> catalog with a row per sequence, and we also create a view named after
>> the sequence that simply selects from pg_sequence with an appropriate
>> WHERE condition.

> I'd think that would be a workable solution, with documentation notes that
> this will be deprecated in favor of information_schema in an upcoming
> release ?

Yeah, we could consider the views a transitional thing, and get rid of
them after a release or two. Tell people to change over to either look
in the pg_sequence catalog, or use the information_schema view. Does
that view expose everything that there is, though, or will we have
proprietary extensions that are not in SQL2003?

regards, tom lane


From: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
To: <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: <darcy(at)wavefire(dot)com>, <pgsql-hackers(at)postgresql(dot)org>, <peter_e(at)gmx(dot)net>
Subject: Re: Accessing schema data in information schema
Date: 2006-03-23 03:50:04
Message-ID: 2998.24.211.165.134.1143085804.squirrel@www.dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Tom Lane said:
> Darcy Buskermolen <darcy(at)wavefire(dot)com> writes:
>> On Wednesday 22 March 2006 13:11, Tom Lane wrote:
>>> (Thinks a bit...) Maybe it would work for pg_sequence to be a real
>>> catalog with a row per sequence, and we also create a view named
>>> after the sequence that simply selects from pg_sequence with an
>>> appropriate WHERE condition.
>
>> I'd think that would be a workable solution, with documentation notes
>> that this will be deprecated in favor of information_schema in an
>> upcoming release ?
>
> Yeah, we could consider the views a transitional thing, and get rid of
> them after a release or two. Tell people to change over to either look
> in the pg_sequence catalog, or use the information_schema view. Does
> that view expose everything that there is, though, or will we have
> proprietary extensions that are not in SQL2003?
>

What happens to sequence ACLs?

cheers

andrew


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Andrew Dunstan" <andrew(at)dunslane(dot)net>
Cc: darcy(at)wavefire(dot)com, pgsql-hackers(at)postgresql(dot)org, peter_e(at)gmx(dot)net
Subject: Re: Accessing schema data in information schema
Date: 2006-03-23 04:14:06
Message-ID: 2592.1143087246@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

"Andrew Dunstan" <andrew(at)dunslane(dot)net> writes:
> What happens to sequence ACLs?

Hm, good point. We could put 'em in pg_sequence, except that most of
the operations on pg_sequence rows will be nontransactional, and that
doesn't seem to square nicely with transactional updates on ACLs.
Maybe we need two catalogs just to separate the transactional and
nontransactional data for a sequence? Ugh.

regards, tom lane


From: Christopher Kings-Lynne <chris(dot)kings-lynne(at)calorieking(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Andrew Dunstan <andrew(at)dunslane(dot)net>, darcy(at)wavefire(dot)com, pgsql-hackers(at)postgresql(dot)org, peter_e(at)gmx(dot)net
Subject: Re: Accessing schema data in information schema
Date: 2006-03-23 04:26:02
Message-ID: 4422235A.9050404@calorieking.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

> Hm, good point. We could put 'em in pg_sequence, except that most of
> the operations on pg_sequence rows will be nontransactional, and that
> doesn't seem to square nicely with transactional updates on ACLs.
> Maybe we need two catalogs just to separate the transactional and
> nontransactional data for a sequence? Ugh.

Is it possible to have an SRF that can peek into the lastval data and
present it, and make no changes to our catalogs at all?

Or can't we use in the schema view something like:

CREATE VIEW sequences AS
SELECT CAST(current_database() AS sql_identifier) AS sequence_catalog,
CAST(nc.nspname AS sql_identifier) AS sequence_schema,
CAST(c.relname AS sql_identifier) AS sequence_name,
(SELECT seq_info('sequence_name', 'max')) AS maximum_value,
(SELECT seq_info('sequence_name', 'min')) AS minimum_value,
(SELECT seq_info('sequence_name', 'inc')) AS increment,
(SELECT seq_info('sequence_name', 'cycle')) AS cycle_option
FROM pg_namespace nc, pg_class c
WHERE c.relnamespace = nc.oid
AND c.relkind = 's';

Chris


From: Hannu Krosing <hannu(at)skype(dot)net>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: tgl(at)sss(dot)pgh(dot)pa(dot)us, darcy(at)wavefire(dot)com, pgsql-hackers(at)postgresql(dot)org, peter_e(at)gmx(dot)net
Subject: Re: Accessing schema data in information schema
Date: 2006-03-23 14:38:17
Message-ID: 1143124698.3985.1.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

Ühel kenal päeval, K, 2006-03-22 kell 21:50, kirjutas Andrew Dunstan:
> Tom Lane said:
> > Darcy Buskermolen <darcy(at)wavefire(dot)com> writes:
> >> On Wednesday 22 March 2006 13:11, Tom Lane wrote:
> >>> (Thinks a bit...) Maybe it would work for pg_sequence to be a real
> >>> catalog with a row per sequence, and we also create a view named
> >>> after the sequence that simply selects from pg_sequence with an
> >>> appropriate WHERE condition.
> >
> >> I'd think that would be a workable solution, with documentation notes
> >> that this will be deprecated in favor of information_schema in an
> >> upcoming release ?
> >
> > Yeah, we could consider the views a transitional thing, and get rid of
> > them after a release or two. Tell people to change over to either look
> > in the pg_sequence catalog, or use the information_schema view. Does
> > that view expose everything that there is, though, or will we have
> > proprietary extensions that are not in SQL2003?
> >
>
> What happens to sequence ACLs?

perhaps we can keep pg_class part of seqs and just make the
pg_class.relfilenode to point to row oid in pg_sequence table ?

-------------
Hannu


From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Hannu Krosing <hannu(at)skype(dot)net>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Accessing schema data in information schema
Date: 2006-03-23 16:31:57
Message-ID: 20060323163157.GQ67996@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-hackers

On Thu, Mar 23, 2006 at 12:10:54AM +0200, Hannu Krosing wrote:
> ??hel kenal p??eval, K, 2006-03-22 kell 16:11, kirjutas Tom Lane:
> > Peter Eisentraut <peter_e(at)gmx(dot)net> writes:
> > > How does one get at the missing fields. The only way I know is
> > > selecting from the sequence, but how does one work this into this
> > > query? Somehow it seems that these things should be stored in a real
> > > system catalog.
> >
> > Yeah. I've occasionally toyed with the idea that sequences should be
> > rows in a single catalog instead of independent tables as they are now.
> > This would make for a much smaller disk footprint (with consequent I/O
> > savings) and would solve problems like the one you have.
>
> Would it not make page locking problems much worse with all get_next()'s
> competeing to update the same page?

What about bumping up the default cache setting a bit? Even going to a
fairly conservative value, like 10 or 25 would probably make a huge
difference.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461