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

Commitf7d7dad

Browse files
committed
Add a transform function for varbit typmod coercisions.
This enables ALTER TABLE to skip table and index rebuilds when thenew type is unconstraint varbit, or when the allowable number of bitsis not decreasing.Noah Misch, with review and a fix for an OID collision by me.
1 parent3cc0800 commitf7d7dad

File tree

4 files changed

+40
-2
lines changed

4 files changed

+40
-2
lines changed

‎src/backend/utils/adt/varbit.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
#include"access/htup.h"
2020
#include"libpq/pqformat.h"
21+
#include"nodes/nodeFuncs.h"
22+
#include"parser/parse_clause.h"
2123
#include"utils/array.h"
2224
#include"utils/varbit.h"
2325

@@ -645,6 +647,39 @@ varbit_send(PG_FUNCTION_ARGS)
645647
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
646648
}
647649

650+
/*
651+
* varbit_transform()
652+
* Flatten calls to our length coercion function that leave the new maximum
653+
* length >= the previous maximum length. We ignore the isExplicit argument,
654+
* which only affects truncation.
655+
*/
656+
Datum
657+
varbit_transform(PG_FUNCTION_ARGS)
658+
{
659+
FuncExpr*expr= (FuncExpr*)PG_GETARG_POINTER(0);
660+
Node*typmod;
661+
Node*ret=NULL;
662+
663+
if (!IsA(expr,FuncExpr))
664+
PG_RETURN_POINTER(ret);
665+
666+
Assert(list_length(expr->args)==3);
667+
typmod=lsecond(expr->args);
668+
669+
if (IsA(typmod,Const))
670+
{
671+
Node*source=linitial(expr->args);
672+
int32new_typmod=DatumGetInt32(((Const*)typmod)->constvalue);
673+
int32old_max=exprTypmod(source);
674+
int32new_max=new_typmod;
675+
676+
if (new_max <=0|| (old_max >=0&&old_max <=new_max))
677+
ret=relabel_to_typmod(source,new_typmod);
678+
}
679+
680+
PG_RETURN_POINTER(ret);
681+
}
682+
648683
/*
649684
* varbit()
650685
* Converts a varbit() type to a specific internal length.

‎src/include/catalog/catversion.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO201202071
56+
#defineCATALOG_VERSION_NO201202072
5757

5858
#endif

‎src/include/catalog/pg_proc.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2009,7 +2009,9 @@ DESCR("convert bitstring to int4");
20092009

20102010
DATA(insertOID=1685 (bitPGNSPPGUID121000ffftfi301560"1560 23 16"_null__null__null__null_bit_null__null__null_ ));
20112011
DESCR("adjust bit() to typmod length");
2012-
DATA(insertOID=1687 (varbitPGNSPPGUID121000ffftfi301562"1562 23 16"_null__null__null__null_varbit_null__null__null_ ));
2012+
DATA(insertOID=3158 (varbit_transformPGNSPPGUID121000ffftfi102281"2281"_null__null__null__null_varbit_transform_null__null__null_ ));
2013+
DESCR("transform a varbit length coercion");
2014+
DATA(insertOID=1687 (varbitPGNSPPGUID121003158ffftfi301562"1562 23 16"_null__null__null__null_varbit_null__null__null_ ));
20132015
DESCR("adjust varbit() to typmod length");
20142016

20152017
DATA(insertOID=1698 (positionPGNSPPGUID121000ffftfi2023"1560 1560"_null__null__null__null_bitposition_null__null__null_ ));

‎src/include/utils/varbit.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ extern Datum varbit_send(PG_FUNCTION_ARGS);
7272
externDatumvarbittypmodin(PG_FUNCTION_ARGS);
7373
externDatumvarbittypmodout(PG_FUNCTION_ARGS);
7474
externDatumbit(PG_FUNCTION_ARGS);
75+
externDatumvarbit_transform(PG_FUNCTION_ARGS);
7576
externDatumvarbit(PG_FUNCTION_ARGS);
7677
externDatumbiteq(PG_FUNCTION_ARGS);
7778
externDatumbitne(PG_FUNCTION_ARGS);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp