Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc1fcce0

Browse files
author
Nikita Malakhov
committed
Toaster API interface with dummy_toaster module.
0002_toaster_interface patchToaster API consists of 4 parts:1) SQL syntax supports manipulations with toasters - add new toaster,assign toaster to a table column.Toaster API requires earlier patch with CREATE TABLE SET STORAGE clause;New column atttoaster is added to pg_attribute.Toaster drop is not allowed for not to lose already toasted data;2) New VARATT_CUSTOM data structure with fixed header and variabletail to store custom toasted data, with according macros set;3) Toaster handler routine structure contains custom toaster functions.Along with necessary functions custom toasters could implement otherfunctions which are stored into vtable;4) Dummy toaster implemented via new Toaster API to be used as sample.In this patch regular (default) toast function is not yet implementedvia new API.Toaster API syntax and code explanation could be found in additional docs patch.Cleaned up log files.Fixed rebase conflict in describe.c describeToastersFixed return values in Dummy toaster from varlena * to DatumIncluded 0007_fix_alignment_of_custom_toast_pointers patch
1 parent7d158e8 commitc1fcce0

File tree

88 files changed

+2516
-741
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+2516
-741
lines changed

‎contrib/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ SUBDIRS = \
1919
dblink\
2020
dict_int\
2121
dict_xsyn\
22+
dummy_toaster\
2223
earthdistance\
2324
file_fdw\
2425
fuzzystrmatch\

‎contrib/dummy_toaster/Makefile‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# contrib/dummy_toaster/Makefile
2+
3+
MODULE_big = dummy_toaster
4+
OBJS =\
5+
$(WIN32RES)\
6+
dummy_toaster.o
7+
8+
EXTENSION = dummy_toaster
9+
DATA = dummy_toaster--1.0.sql
10+
PGFILEDESC = "dummy_toaster - toaster example"
11+
12+
REGRESS = dummy_toaster
13+
14+
ifdefUSE_PGXS
15+
PG_CONFIG = pg_config
16+
PGXS :=$(shell$(PG_CONFIG) --pgxs)
17+
include$(PGXS)
18+
else
19+
subdir = contrib/dummy_toaster
20+
top_builddir = ../..
21+
include$(top_builddir)/src/Makefile.global
22+
include$(top_srcdir)/contrib/contrib-global.mk
23+
endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/* contrib/bloom/bloom--1.0.sql*/
2+
3+
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
4+
\echo Use"CREATE EXTENSION dummy_toaster" to load this file. \quit
5+
6+
CREATEFUNCTIONdummy_toaster_handler(internal)
7+
RETURNS toaster_handler
8+
AS'MODULE_PATHNAME'
9+
LANGUAGE C;
10+
11+
12+
CREATE TOASTER dummy_toaster HANDLER dummy_toaster_handler;
13+
14+
COMMENTON TOASTER dummy_toaster IS'dummy_toaster is a dummy toaster';
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*-------------------------------------------------------------------------
2+
*
3+
* dummy_toaster.c
4+
*Dummy toaster for Toaster API.
5+
*
6+
* Portions Copyright (c) 2016-2021, PostgreSQL Global Development Group
7+
* Portions Copyright (c) 1990-1993, Regents of the University of California
8+
*
9+
* IDENTIFICATION
10+
* contrib/dummy_toaster/dummy_toaster.c
11+
*
12+
*-------------------------------------------------------------------------
13+
*/
14+
#include"postgres.h"
15+
#include"fmgr.h"
16+
#include"access/toasterapi.h"
17+
#include"nodes/makefuncs.h"
18+
19+
PG_MODULE_MAGIC;
20+
PG_FUNCTION_INFO_V1(dummy_toaster_handler);
21+
22+
#defineMAX_DUMMY_CHUNK_SIZE 1024
23+
24+
/*
25+
* Dummy Toaster is a sample custom toaster for developers to show Toaster API
26+
* functionality and correct way to add new Toasters to PgSQL.
27+
*/
28+
29+
30+
/*
31+
* Dummy detoast function, does nothing
32+
*/
33+
staticDatum
34+
dummy_detoast(Relationtoast_rel,Datumtoast_ptr,
35+
intoffset,intlength)
36+
{
37+
structvarlena*result;
38+
result=palloc(0);
39+
returnPointerGetDatum(result);
40+
}
41+
42+
/*
43+
* Dummy Toast function, does nothing
44+
*/
45+
staticDatum
46+
dummy_toast(Relationtoast_rel,Oidtoasterid,
47+
Datumvalue,Datumoldvalue,
48+
intmax_inline_size,intoptions)
49+
{
50+
structvarlena*result;
51+
result=palloc(0);
52+
returnPointerGetDatum(result);
53+
}
54+
55+
/*
56+
* Dummy deltoast function, does nothing
57+
*/
58+
staticvoid
59+
dummy_delete(Datumvalue,boolis_speculative)
60+
{
61+
}
62+
63+
/*
64+
* Dummy init function, does nothing
65+
*/
66+
staticvoid
67+
dummy_toast_init(Relationrel,Datumreloptions,LOCKMODElockmode,
68+
boolcheck,OidOIDOldToast)
69+
{
70+
}
71+
72+
/*
73+
* Dummy validation function, always returns TRUE
74+
*/
75+
staticbool
76+
dummy_toaster_validate(Oidtypeoid,charstorage,charcompression,
77+
Oidamoid,boolfalse_ok)
78+
{
79+
return true;
80+
}
81+
82+
/*
83+
* Dummy toaster handler.
84+
* All Toaster functions declared in toasterapi.h and implemented in Custom
85+
* Toasters must be assigned to TsrRoutine structure
86+
*/
87+
Datum
88+
dummy_toaster_handler(PG_FUNCTION_ARGS)
89+
{
90+
TsrRoutine*tsr=makeNode(TsrRoutine);
91+
tsr->init=dummy_toast_init;
92+
tsr->toast=dummy_toast;
93+
tsr->update_toast=NULL;
94+
tsr->copy_toast=NULL;
95+
tsr->detoast=dummy_detoast;
96+
tsr->deltoast=dummy_delete;
97+
tsr->get_vtable=NULL;
98+
tsr->toastervalidate=NULL;
99+
100+
PG_RETURN_POINTER(tsr);
101+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# dummy_toaster extension
2+
comment = 'dummy_toaster - dummy toaster'
3+
default_version = '1.0'
4+
module_pathname = '$libdir/dummy_toaster'
5+
relocatable = true
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
CREATE EXTENSION dummy_toaster;
2+
CREATE TABLE tst_failed (
3+
t text TOASTER dummy_toaster TOASTER dummy_toaster
4+
);
5+
ERROR: multiple TOASTER clauses not allowed
6+
CREATE TABLE tst1 (
7+
t text TOASTER dummy_toaster
8+
);
9+
SELECT attnum, attname, atttypid, attstorage, tsrname
10+
FROM pg_attribute, pg_toaster t
11+
WHERE attrelid = 'tst1'::regclass and attnum>0 and t.oid = atttoaster
12+
ORDER BY attnum;
13+
attnum | attname | atttypid | attstorage | tsrname
14+
--------+---------+----------+------------+---------------
15+
1 | t | 25 | x | dummy_toaster
16+
(1 row)
17+
18+
CREATE TABLE tst2 (
19+
ttext
20+
);
21+
SELECT attnum, attname, atttypid, attstorage, tsrname
22+
FROM pg_attribute, pg_toaster t
23+
WHERE attrelid = 'tst2'::regclass and attnum>0 and t.oid = atttoaster
24+
ORDER BY attnum;
25+
attnum | attname | atttypid | attstorage | tsrname
26+
--------+---------+----------+------------+------------
27+
1 | t | 25 | x | deftoaster
28+
(1 row)
29+
30+
ALTER TABLE tst2 ALTER COLUMN t SET TOASTER dummy_toaster;
31+
SELECT attnum, attname, atttypid, attstorage, tsrname
32+
FROM pg_attribute, pg_toaster t
33+
WHERE attrelid = 'tst2'::regclass and attnum>0 and t.oid = atttoaster
34+
ORDER BY attnum;
35+
attnum | attname | atttypid | attstorage | tsrname
36+
--------+---------+----------+------------+---------------
37+
1 | t | 25 | x | dummy_toaster
38+
(1 row)
39+
40+
\d+ tst1
41+
Table "public.tst1"
42+
Column | Type | Collation | Nullable | Default | Storage | Toaster | Stats target | Description
43+
--------+------+-----------+----------+---------+----------+---------------+--------------+-------------
44+
t | text | | | | extended | dummy_toaster | |
45+
46+
\d+ tst2
47+
Table "public.tst2"
48+
Column | Type | Collation | Nullable | Default | Storage | Toaster | Stats target | Description
49+
--------+------+-----------+----------+---------+----------+---------------+--------------+-------------
50+
t | text | | | | extended | dummy_toaster | |
51+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
CREATE EXTENSION dummy_toaster;
2+
3+
CREATETABLEtst_failed (
4+
ttext TOASTER dummy_toaster TOASTER dummy_toaster
5+
);
6+
7+
CREATETABLEtst1 (
8+
ttext TOASTER dummy_toaster
9+
);
10+
11+
SELECT attnum, attname, atttypid, attstorage, tsrname
12+
FROM pg_attribute, pg_toaster t
13+
WHERE attrelid='tst1'::regclassand attnum>0andt.oid= atttoaster
14+
ORDER BY attnum;
15+
16+
CREATETABLEtst2 (
17+
ttext
18+
);
19+
20+
SELECT attnum, attname, atttypid, attstorage, tsrname
21+
FROM pg_attribute, pg_toaster t
22+
WHERE attrelid='tst2'::regclassand attnum>0andt.oid= atttoaster
23+
ORDER BY attnum;
24+
25+
ALTERTABLE tst2 ALTER COLUMN tSET TOASTER dummy_toaster;
26+
27+
SELECT attnum, attname, atttypid, attstorage, tsrname
28+
FROM pg_attribute, pg_toaster t
29+
WHERE attrelid='tst2'::regclassand attnum>0andt.oid= atttoaster
30+
ORDER BY attnum;
31+
32+
\d+ tst1
33+
\d+ tst2

‎contrib/test_decoding/expected/ddl.out‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -484,12 +484,12 @@ CREATE TABLE replication_metadata (
484484
WITH (user_catalog_table = true)
485485
;
486486
\d+ replication_metadata
487-
Table "public.replication_metadata"
488-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
489-
----------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
490-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
491-
relation | name | | not null | | plain | |
492-
options | text[] | | | | extended | |
487+
Table "public.replication_metadata"
488+
Column | Type | Collation | Nullable | Default | Storage | Toaster |Stats target | Description
489+
----------+---------+-----------+----------+--------------------------------------------------+----------+------------+--------------+-------------
490+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain || |
491+
relation | name | | not null | | plain || |
492+
options | text[] | | | | extended |deftoaster | |
493493
Indexes:
494494
"replication_metadata_pkey" PRIMARY KEY, btree (id)
495495
Options: user_catalog_table=true
@@ -498,25 +498,25 @@ INSERT INTO replication_metadata(relation, options)
498498
VALUES ('foo', ARRAY['a', 'b']);
499499
ALTER TABLE replication_metadata RESET (user_catalog_table);
500500
\d+ replication_metadata
501-
Table "public.replication_metadata"
502-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
503-
----------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
504-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
505-
relation | name | | not null | | plain | |
506-
options | text[] | | | | extended | |
501+
Table "public.replication_metadata"
502+
Column | Type | Collation | Nullable | Default | Storage | Toaster |Stats target | Description
503+
----------+---------+-----------+----------+--------------------------------------------------+----------+------------+--------------+-------------
504+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain || |
505+
relation | name | | not null | | plain || |
506+
options | text[] | | | | extended |deftoaster | |
507507
Indexes:
508508
"replication_metadata_pkey" PRIMARY KEY, btree (id)
509509

510510
INSERT INTO replication_metadata(relation, options)
511511
VALUES ('bar', ARRAY['a', 'b']);
512512
ALTER TABLE replication_metadata SET (user_catalog_table = true);
513513
\d+ replication_metadata
514-
Table "public.replication_metadata"
515-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
516-
----------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
517-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
518-
relation | name | | not null | | plain | |
519-
options | text[] | | | | extended | |
514+
Table "public.replication_metadata"
515+
Column | Type | Collation | Nullable | Default | Storage | Toaster |Stats target | Description
516+
----------+---------+-----------+----------+--------------------------------------------------+----------+------------+--------------+-------------
517+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain || |
518+
relation | name | | not null | | plain || |
519+
options | text[] | | | | extended |deftoaster | |
520520
Indexes:
521521
"replication_metadata_pkey" PRIMARY KEY, btree (id)
522522
Options: user_catalog_table=true
@@ -529,13 +529,13 @@ ALTER TABLE replication_metadata ALTER COLUMN rewritemeornot TYPE text;
529529
ERROR: cannot rewrite table "replication_metadata" used as a catalog table
530530
ALTER TABLE replication_metadata SET (user_catalog_table = false);
531531
\d+ replication_metadata
532-
Table "public.replication_metadata"
533-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
534-
----------------+---------+-----------+----------+--------------------------------------------------+----------+--------------+-------------
535-
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain | |
536-
relation | name | | not null | | plain | |
537-
options | text[] | | | | extended | |
538-
rewritemeornot | integer | | | | plain | |
532+
Table "public.replication_metadata"
533+
Column | Type | Collation | Nullable | Default | Storage | Toaster |Stats target | Description
534+
----------------+---------+-----------+----------+--------------------------------------------------+----------+------------+--------------+-------------
535+
id | integer | | not null | nextval('replication_metadata_id_seq'::regclass) | plain || |
536+
relation | name | | not null | | plain || |
537+
options | text[] | | | | extended |deftoaster | |
538+
rewritemeornot | integer | | | | plain || |
539539
Indexes:
540540
"replication_metadata_pkey" PRIMARY KEY, btree (id)
541541
Options: user_catalog_table=false

‎src/backend/access/common/tupdesc.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include"access/toast_compression.h"
2424
#include"access/tupdesc_details.h"
2525
#include"catalog/pg_collation.h"
26+
#include"catalog/pg_toaster.h"
2627
#include"catalog/pg_type.h"
2728
#include"common/hashfn.h"
2829
#include"miscadmin.h"
@@ -31,6 +32,7 @@
3132
#include"utils/builtins.h"
3233
#include"utils/datum.h"
3334
#include"utils/resowner_private.h"
35+
#include"utils/lsyscache.h"
3436
#include"utils/syscache.h"
3537

3638

@@ -445,6 +447,8 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
445447
return false;
446448
if (attr1->attstorage!=attr2->attstorage)
447449
return false;
450+
if (attr1->atttoaster!=attr2->atttoaster)
451+
return false;
448452
if (attr1->attcompression!=attr2->attcompression)
449453
return false;
450454
if (attr1->attnotnull!=attr2->attnotnull)
@@ -642,6 +646,8 @@ TupleDescInitEntry(TupleDesc desc,
642646
att->attbyval=typeForm->typbyval;
643647
att->attalign=typeForm->typalign;
644648
att->attstorage=typeForm->typstorage;
649+
att->atttoaster=TypeIsToastable(oidtypeid) ?
650+
DEFAULT_TOASTER_OID :InvalidOid;
645651
att->attcompression=InvalidCompressionMethod;
646652
att->attcollation=typeForm->typcollation;
647653

@@ -708,6 +714,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
708714
att->attbyval= false;
709715
att->attalign=TYPALIGN_INT;
710716
att->attstorage=TYPSTORAGE_EXTENDED;
717+
att->atttoaster=DEFAULT_TOASTER_OID;
711718
att->attcompression=InvalidCompressionMethod;
712719
att->attcollation=DEFAULT_COLLATION_OID;
713720
break;
@@ -717,6 +724,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
717724
att->attbyval= true;
718725
att->attalign=TYPALIGN_CHAR;
719726
att->attstorage=TYPSTORAGE_PLAIN;
727+
att->atttoaster=DEFAULT_TOASTER_OID;
720728
att->attcompression=InvalidCompressionMethod;
721729
att->attcollation=InvalidOid;
722730
break;
@@ -726,6 +734,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
726734
att->attbyval= true;
727735
att->attalign=TYPALIGN_INT;
728736
att->attstorage=TYPSTORAGE_PLAIN;
737+
att->atttoaster=DEFAULT_TOASTER_OID;
729738
att->attcompression=InvalidCompressionMethod;
730739
att->attcollation=InvalidOid;
731740
break;
@@ -735,6 +744,7 @@ TupleDescInitBuiltinEntry(TupleDesc desc,
735744
att->attbyval=FLOAT8PASSBYVAL;
736745
att->attalign=TYPALIGN_DOUBLE;
737746
att->attstorage=TYPSTORAGE_PLAIN;
747+
att->atttoaster=DEFAULT_TOASTER_OID;
738748
att->attcompression=InvalidCompressionMethod;
739749
att->attcollation=InvalidOid;
740750
break;

‎src/backend/access/index/Makefile‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ OBJS = \
1616
amapi.o\
1717
amvalidate.o\
1818
genam.o\
19-
indexam.o
19+
indexam.o\
20+
toasterapi.o
2021

2122
include$(top_srcdir)/src/backend/common.mk

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp