pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Why does the OID jump by 3 when creating tables?
4+ messages / 3 participants
[nested] [flat]

* Why does the OID jump by 3 when creating tables?
@ 2021-10-30 08:55  Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Daniel Westermann (DWE) @ 2021-10-30 08:55 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi all,

as I could not find the reason in the source code, can someone tell me why the OID counter jumps by 3 between two create table statements?

postgres=# create table t1 ( a int );
CREATE TABLE
postgres=# create table t2 ( a int );
CREATE TABLE
postgres=# select oid,relname from pg_class where relname in ('t1','t2');
  oid  | relname 
-------+---------
 16453 | t1
 16456 | t2
(2 rows)

These seems not to happen with other objects, e.g. namespaces:

postgres=# create schema a;
CREATE SCHEMA
postgres=# create schema b;
CREATE SCHEMA
postgres=# select oid,nspname from pg_namespace where nspname in ('a','b');
  oid  | nspname 
-------+---------
 16459 | a
 16460 | b
(2 rows)

... or indexes:

postgres=# select oid,relname from pg_class where relname in ('i1','i2');
  oid  | relname 
-------+---------
 16461 | i1
 16462 | i2

Thanks in advance
Daniel





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Why does the OID jump by 3 when creating tables?
@ 2021-10-30 09:51  Guillaume Lelarge <guillaume@lelarge.info>
  parent: Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Guillaume Lelarge @ 2021-10-30 09:51 UTC (permalink / raw)
  To: Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

Hi,

Le sam. 30 oct. 2021 à 10:55, Daniel Westermann (DWE) <
daniel.westermann@dbi-services.com> a écrit :

> Hi all,
>
> as I could not find the reason in the source code, can someone tell me why
> the OID counter jumps by 3 between two create table statements?
>
> postgres=# create table t1 ( a int );
> CREATE TABLE
> postgres=# create table t2 ( a int );
> CREATE TABLE
> postgres=# select oid,relname from pg_class where relname in ('t1','t2');
>   oid  | relname
> -------+---------
>  16453 | t1
>  16456 | t2
> (2 rows)
>
> These seems not to happen with other objects, e.g. namespaces:
>
> postgres=# create schema a;
> CREATE SCHEMA
> postgres=# create schema b;
> CREATE SCHEMA
> postgres=# select oid,nspname from pg_namespace where nspname in ('a','b');
>   oid  | nspname
> -------+---------
>  16459 | a
>  16460 | b
> (2 rows)
>
> ... or indexes:
>
> postgres=# select oid,relname from pg_class where relname in ('i1','i2');
>   oid  | relname
> -------+---------
>  16461 | i1
>  16462 | i2
>
>
When you create a table, it also creates two data types: tablename and
_tablename. For example, for your table t1, you should have a t1 type and a
_t1 type. Both have OIDs. On my cluster, your example gives me:

# select oid,relname from pg_class where relname in ('t1','t2');
┌───────┬─────────┐
│  oid  │ relname │
├───────┼─────────┤
│ 24635 │ t1      │
│ 24638 │ t2      │
└───────┴─────────┘
(2 rows)

Time: 0.507 ms
# select oid, typname from pg_type where typname like '%t1' or typname like
'%t2' and oid>24000 order by oid;
┌───────┬─────────┐
│  oid  │ typname │
├───────┼─────────┤
│ 24636 │ _t1     │
│ 24637 │ t1      │
│ 24639 │ _t2     │
│ 24640 │ t2      │
└───────┴─────────┘
(4 rows)

Time: 1.203 ms

The jump between t1 OID (24635) and t2 OID (24638) is the _t1 data type OID
(24636) and the t1 data type OID (24637).


-- 
Guillaume.


^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Why does the OID jump by 3 when creating tables?
@ 2021-10-30 10:20  Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>
  parent: Guillaume Lelarge <guillaume@lelarge.info>
  0 siblings, 0 replies; 4+ messages in thread

From: Daniel Westermann (DWE) @ 2021-10-30 10:20 UTC (permalink / raw)
  To: Guillaume Lelarge <guillaume@lelarge.info>; +Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>

>>Le sam. 30 oct. 2021 à 10:55, Daniel Westermann (DWE) <daniel.westermann@dbi-services.com> a écrit :
>>Hi all,

>>as I could not find the reason in the source code, can someone tell me why the OID counter jumps by 3 between two create table >>statements?

>>postgres=# create table t1 ( a int );
>>CREATE TABLE
>>postgres=# create table t2 ( a int );
>>CREATE TABLE
>>postgres=# select oid,relname from pg_class where relname in ('t1','t2');
>>  oid  | relname 
>>-------+---------
>> 16453 | t1
>> 16456 | t2
>>(2 rows)

>>These seems not to happen with other objects, e.g. namespaces:

>>postgres=# create schema a;
>>CREATE SCHEMA
>>postgres=# create schema b;
>>CREATE SCHEMA
>>postgres=# select oid,nspname from pg_namespace where nspname in ('a','b');
>>  oid  | nspname 
>>-------+---------
>> 16459 | a
>> 16460 | b
>>(2 rows)

>>... or indexes:

>>postgres=# select oid,relname from pg_class where relname in ('i1','i2');
>>  oid  | relname 
>>-------+---------
>> 16461 | i1
>> 16462 | i2


>When you create a table, it also creates two data types: tablename and _tablename. For example, for your table t1, you should have a >t1 type and a _t1 type. Both have OIDs. On my cluster, your example gives me:

># select oid,relname from pg_class where relname in ('t1','t2');
>┌───────┬─────────┐
>│  oid  │ relname │
>├───────┼─────────┤
>│ 24635 │ t1      │
>│ 24638 │ t2      │
>└───────┴─────────┘
>(2 rows)

>Time: 0.507 ms
># select oid, typname from pg_type where typname like '%t1' or typname like '%t2' and oid>24000 order by oid;
>┌───────┬─────────┐
>│  oid  │ typname │
>├───────┼─────────┤
>│ 24636 │ _t1     │
>│ 24637 │ t1      │
>│ 24639 │ _t2     │
>│ 24640 │ t2      │
>└───────┴─────────┘
>(4 rows)

>Time: 1.203 ms

>The jump between t1 OID (24635) and t2 OID (24638) is the _t1 data type OID (24636) and the t1 data type OID (24637).

Thank you, Guillaume. 

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Why does the OID jump by 3 when creating tables?
@ 2021-10-30 15:04  Ron <ronljohnsonjr@gmail.com>
  parent: Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Ron @ 2021-10-30 15:04 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

On 10/30/21 3:55 AM, Daniel Westermann (DWE) wrote:
> Hi all,
>
> as I could not find the reason in the source code, can someone tell me why the OID counter jumps by 3 between two create table statements?
>
> postgres=# create table t1 ( a int );
> CREATE TABLE
> postgres=# create table t2 ( a int );
> CREATE TABLE
> postgres=# select oid,relname from pg_class where relname in ('t1','t2');
>    oid  | relname
> -------+---------
>   16453 | t1
>   16456 | t2
> (2 rows)
>
> These seems not to happen with other objects, e.g. namespaces:
>
> postgres=# create schema a;
> CREATE SCHEMA
> postgres=# create schema b;
> CREATE SCHEMA
> postgres=# select oid,nspname from pg_namespace where nspname in ('a','b');
>    oid  | nspname
> -------+---------
>   16459 | a
>   16460 | b
> (2 rows)
>
> ... or indexes:
>
> postgres=# select oid,relname from pg_class where relname in ('i1','i2');
>    oid  | relname
> -------+---------
>   16461 | i1
>   16462 | i2
>

I'd run this, and see if the results answer the question:

select oid,relname, reltype from pg_class where oid between 16453 and 16455;

-- 
Angular momentum makes the world go 'round.





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2021-10-30 15:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-30 08:55 Why does the OID jump by 3 when creating tables? Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>
2021-10-30 09:51 ` Guillaume Lelarge <guillaume@lelarge.info>
2021-10-30 10:20   ` Daniel Westermann (DWE) <daniel.westermann@dbi-services.com>
2021-10-30 15:04 ` Ron <ronljohnsonjr@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox