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

Commit1bec314

Browse files
author
Nikita Malakhov
committed
Default (generic) toaster re-implemented using Toaster API.
Default Toaster could be replaced with custom toaster bySET TOASTER clause in CREATE TABLE or ALTER TABLE expressionAdded src/backend/access/toast/README.toastapi0003_toaster_default patch
1 parentc1fcce0 commit1bec314

File tree

50 files changed

+2430
-1204
lines changed

Some content is hidden

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

50 files changed

+2430
-1204
lines changed

‎contrib/amcheck/verify_heapam.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111
#include"postgres.h"
1212

13-
#include"access/detoast.h"
13+
#include"access/toasterapi.h"
1414
#include"access/genam.h"
1515
#include"access/heapam.h"
1616
#include"access/heaptoast.h"
@@ -24,6 +24,8 @@
2424
#include"storage/procarray.h"
2525
#include"utils/builtins.h"
2626
#include"utils/fmgroids.h"
27+
#include"access/toast_helper.h"
28+
#include"catalog/toasting.h"
2729

2830
PG_FUNCTION_INFO_V1(verify_heapam);
2931

‎contrib/dummy_toaster/dummy_toaster--1.0.sql‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ LANGUAGE C;
1212
CREATE TOASTER dummy_toaster HANDLER dummy_toaster_handler;
1313

1414
COMMENTON TOASTER dummy_toaster IS'dummy_toaster is a dummy toaster';
15+
Lines changed: 85 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*-------------------------------------------------------------------------
22
*
33
* dummy_toaster.c
4-
*Dummy toaster for Toaster API.
4+
*Dummy toaster- sample toasterfor Toaster API.
55
*
66
* Portions Copyright (c) 2016-2021, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1990-1993, Regents of the University of California
@@ -14,6 +14,26 @@
1414
#include"postgres.h"
1515
#include"fmgr.h"
1616
#include"access/toasterapi.h"
17+
#include"access/heaptoast.h"
18+
#include"access/htup_details.h"
19+
#include"catalog/pg_toaster.h"
20+
#include"commands/defrem.h"
21+
#include"utils/builtins.h"
22+
#include"utils/syscache.h"
23+
#include"access/toast_compression.h"
24+
#include"access/xact.h"
25+
#include"catalog/binary_upgrade.h"
26+
#include"catalog/catalog.h"
27+
#include"catalog/dependency.h"
28+
#include"catalog/heap.h"
29+
#include"catalog/index.h"
30+
#include"catalog/namespace.h"
31+
#include"catalog/pg_am.h"
32+
#include"catalog/pg_namespace.h"
33+
#include"catalog/pg_opclass.h"
34+
#include"catalog/pg_type.h"
35+
#include"catalog/toasting.h"
36+
#include"miscadmin.h"
1737
#include"nodes/makefuncs.h"
1838

1939
PG_MODULE_MAGIC;
@@ -22,68 +42,106 @@ PG_FUNCTION_INFO_V1(dummy_toaster_handler);
2242
#defineMAX_DUMMY_CHUNK_SIZE 1024
2343

2444
/*
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
45+
* Dummy Detoast function, receives single varatt_custom pointer,
46+
* detoasts it to varlena.
47+
*
3248
*/
3349
staticDatum
34-
dummy_detoast(Relationtoast_rel,Datumtoast_ptr,
50+
dummy_detoast(Datumtoast_ptr,
3551
intoffset,intlength)
3652
{
53+
structvarlena*attr= (structvarlena*)DatumGetPointer(toast_ptr);
3754
structvarlena*result;
38-
result=palloc(0);
55+
56+
Assert(VARATT_IS_EXTERNAL(attr));
57+
Assert(VARATT_IS_CUSTOM(attr));
58+
59+
result=palloc(VARATT_CUSTOM_GET_DATA_RAW_SIZE(attr));
60+
SET_VARSIZE(result,VARATT_CUSTOM_GET_DATA_RAW_SIZE(attr));
61+
memcpy(VARDATA(result),VARATT_CUSTOM_GET_DATA(attr),
62+
VARATT_CUSTOM_GET_DATA_RAW_SIZE(attr)-VARHDRSZ);
63+
3964
returnPointerGetDatum(result);
4065
}
4166

4267
/*
43-
* Dummy Toast function, does nothing
68+
* Dummy Toast function, receives varlena pointer, creates single varatt_custom
69+
* varlena size is limited to 1024 bytes
4470
*/
4571
staticDatum
4672
dummy_toast(Relationtoast_rel,Oidtoasterid,
4773
Datumvalue,Datumoldvalue,
4874
intmax_inline_size,intoptions)
4975
{
76+
structvarlena*attr;
5077
structvarlena*result;
51-
result=palloc(0);
78+
intlen;
79+
attr=pg_detoast_datum((structvarlena*)DatumGetPointer(value));
80+
81+
if(VARSIZE_ANY_EXHDR(attr)>MAX_DUMMY_CHUNK_SIZE)
82+
{
83+
ereport(ERROR,
84+
(errcode(ERRCODE_DATA_CORRUPTED),
85+
errmsg_internal("Data <%d> size exceeds MAX_DUMMY_CHUNK_SIZE <%d>",
86+
(int)VARSIZE_ANY_EXHDR(attr),MAX_DUMMY_CHUNK_SIZE)));
87+
88+
}
89+
90+
len=VARATT_CUSTOM_SIZE(VARSIZE_ANY_EXHDR(attr));
91+
92+
if (max_inline_size>0&&len>max_inline_size)
93+
{
94+
ereport(ERROR,
95+
(errcode(ERRCODE_DATA_CORRUPTED),
96+
errmsg_internal("Data <%d> size exceeds max inline size <%d>",
97+
len,max_inline_size)));
98+
}
99+
100+
result=palloc(len);
101+
102+
SET_VARTAG_EXTERNAL(result,VARTAG_CUSTOM);
103+
VARATT_CUSTOM_SET_DATA_RAW_SIZE(result,VARSIZE_ANY_EXHDR(attr)+VARHDRSZ);
104+
VARATT_CUSTOM_SET_DATA_SIZE(result,len);
105+
VARATT_CUSTOM_SET_TOASTERID(result,toasterid);
106+
107+
memcpy(VARATT_CUSTOM_GET_DATA(result),VARDATA_ANY(attr),
108+
VARSIZE_ANY_EXHDR(attr));
109+
110+
if ((char*)attr!=DatumGetPointer(value))
111+
pfree(attr);
112+
52113
returnPointerGetDatum(result);
53114
}
54115

55116
/*
56-
* Dummydeltoast function, does nothing
117+
* Dummydelete function
57118
*/
58119
staticvoid
59120
dummy_delete(Datumvalue,boolis_speculative)
60121
{
61122
}
62123

63124
/*
64-
* Dummy init function, does nothing
125+
* Dummy Validate, always returns True
126+
*
65127
*/
66-
staticvoid
67-
dummy_toast_init(Relationrel,Datumreloptions,LOCKMODElockmode,
68-
boolcheck,OidOIDOldToast)
128+
staticbool
129+
dummy_toaster_validate(Oidtypeoid,charstorage,charcompression,
130+
Oidamoid,boolfalse_ok)
69131
{
132+
boolresult= true;
133+
returnresult;
70134
}
71135

72136
/*
73137
* Dummy validation function, always returns TRUE
74138
*/
75-
staticbool
76-
dummy_toaster_validate(Oidtypeoid,charstorage,charcompression,
77-
Oidamoid,boolfalse_ok)
139+
staticvoid
140+
dummy_toast_init(Relationrel,Oidtoastoid,Oidtoastindexoid,Datumreloptions,LOCKMODElockmode,
141+
boolcheck,OidOIDOldToast)
78142
{
79-
return true;
80143
}
81144

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-
*/
87145
Datum
88146
dummy_toaster_handler(PG_FUNCTION_ARGS)
89147
{
@@ -95,7 +153,7 @@ dummy_toaster_handler(PG_FUNCTION_ARGS)
95153
tsr->detoast=dummy_detoast;
96154
tsr->deltoast=dummy_delete;
97155
tsr->get_vtable=NULL;
98-
tsr->toastervalidate=NULL;
156+
tsr->toastervalidate=dummy_toaster_validate;
99157

100158
PG_RETURN_POINTER(tsr);
101159
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp