Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
postgres-lambda-diff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jakob Huber
postgres-lambda-diff
Commits
55f7d4ea
Commit
55f7d4ea
authored
27 years ago
by
Vadim B. Mikheev
Browse files
Options
Downloads
Patches
Plain Diff
CreateTupleDescCopy don't copy constraints now!
+ CreateTupleDescCopyConstr to copy them too. + FreeTupleDesc
parent
76501c8a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/backend/access/common/tupdesc.c
+161
-14
161 additions, 14 deletions
src/backend/access/common/tupdesc.c
with
161 additions
and
14 deletions
src/backend/access/common/tupdesc.c
+
161
−
14
View file @
55f7d4ea
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.1
8
1997/08/2
1 14:33:05 momjian
Exp $
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.1
9
1997/08/2
2 02:55:39 vadim
Exp $
*
*
* NOTES
* NOTES
* some of the executor utility code such as "ExecTypeFromTL" should be
* some of the executor utility code such as "ExecTypeFromTL" should be
...
@@ -99,6 +99,7 @@ CreateTupleDesc(int natts, AttributeTupleForm* attrs)
...
@@ -99,6 +99,7 @@ CreateTupleDesc(int natts, AttributeTupleForm* attrs)
* This function creates a new TupleDesc by copying from an existing
* This function creates a new TupleDesc by copying from an existing
* TupleDesc
* TupleDesc
*
*
* !!! Constraints are not copied !!!
* ----------------------------------------------------------------
* ----------------------------------------------------------------
*/
*/
TupleDesc
TupleDesc
...
@@ -117,15 +118,127 @@ CreateTupleDescCopy(TupleDesc tupdesc)
...
@@ -117,15 +118,127 @@ CreateTupleDescCopy(TupleDesc tupdesc)
memmove
(
desc
->
attrs
[
i
],
memmove
(
desc
->
attrs
[
i
],
tupdesc
->
attrs
[
i
],
tupdesc
->
attrs
[
i
],
ATTRIBUTE_TUPLE_SIZE
);
ATTRIBUTE_TUPLE_SIZE
);
desc
->
attrs
[
i
]
->
attnotnull
=
false
;
desc
->
attrs
[
i
]
->
atthasdef
=
false
;
}
}
if
(
tupdesc
->
constr
)
{
desc
->
constr
=
NULL
;
desc
->
constr
=
(
TupleConstr
*
)
palloc
(
sizeof
(
TupleConstr
));
memmove
(
desc
->
constr
,
tupdesc
->
constr
,
sizeof
(
TupleConstr
));
}
else
desc
->
constr
=
NULL
;
return
desc
;
return
desc
;
}
}
/* ----------------------------------------------------------------
* CreateTupleDescCopyConstr
*
* This function creates a new TupleDesc by copying from an existing
* TupleDesc (with Constraints)
*
* ----------------------------------------------------------------
*/
TupleDesc
CreateTupleDescCopyConstr
(
TupleDesc
tupdesc
)
{
TupleDesc
desc
;
TupleConstr
*
constr
=
tupdesc
->
constr
;
int
i
,
size
;
desc
=
(
TupleDesc
)
palloc
(
sizeof
(
struct
tupleDesc
));
desc
->
natts
=
tupdesc
->
natts
;
size
=
desc
->
natts
*
sizeof
(
AttributeTupleForm
);
desc
->
attrs
=
(
AttributeTupleForm
*
)
palloc
(
size
);
for
(
i
=
0
;
i
<
desc
->
natts
;
i
++
)
{
desc
->
attrs
[
i
]
=
(
AttributeTupleForm
)
palloc
(
ATTRIBUTE_TUPLE_SIZE
);
memmove
(
desc
->
attrs
[
i
],
tupdesc
->
attrs
[
i
],
ATTRIBUTE_TUPLE_SIZE
);
}
if
(
constr
)
{
TupleConstr
*
cpy
=
(
TupleConstr
*
)
palloc
(
sizeof
(
TupleConstr
));
cpy
->
has_not_null
=
constr
->
has_not_null
;
if
(
(
cpy
->
num_defval
=
constr
->
num_defval
)
>
0
)
{
cpy
->
defval
=
(
AttrDefault
*
)
palloc
(
cpy
->
num_defval
*
sizeof
(
AttrDefault
));
memcpy
(
cpy
->
defval
,
constr
->
defval
,
cpy
->
num_defval
*
sizeof
(
AttrDefault
));
for
(
i
=
cpy
->
num_defval
-
1
;
i
>=
0
;
i
--
)
{
if
(
constr
->
defval
[
i
].
adbin
)
cpy
->
defval
[
i
].
adbin
=
pstrdup
(
constr
->
defval
[
i
].
adbin
);
if
(
constr
->
defval
[
i
].
adsrc
)
cpy
->
defval
[
i
].
adsrc
=
pstrdup
(
constr
->
defval
[
i
].
adsrc
);
}
}
if
(
(
cpy
->
num_check
=
constr
->
num_check
)
>
0
)
{
cpy
->
check
=
(
ConstrCheck
*
)
palloc
(
cpy
->
num_check
*
sizeof
(
ConstrCheck
));
memcpy
(
cpy
->
check
,
constr
->
check
,
cpy
->
num_check
*
sizeof
(
ConstrCheck
));
for
(
i
=
cpy
->
num_check
-
1
;
i
>=
0
;
i
--
)
{
if
(
constr
->
check
[
i
].
ccname
)
cpy
->
check
[
i
].
ccname
=
pstrdup
(
constr
->
check
[
i
].
ccname
);
if
(
constr
->
check
[
i
].
ccbin
)
cpy
->
check
[
i
].
ccbin
=
pstrdup
(
constr
->
check
[
i
].
ccbin
);
if
(
constr
->
check
[
i
].
ccsrc
)
cpy
->
check
[
i
].
ccsrc
=
pstrdup
(
constr
->
check
[
i
].
ccsrc
);
}
}
desc
->
constr
=
cpy
;
}
else
desc
->
constr
=
NULL
;
return
desc
;
}
void
FreeTupleDesc
(
TupleDesc
tupdesc
)
{
int
i
;
for
(
i
=
0
;
i
<
tupdesc
->
natts
;
i
++
)
pfree
(
tupdesc
->
attrs
[
i
]);
pfree
(
tupdesc
->
attrs
);
if
(
tupdesc
->
constr
)
{
if
(
tupdesc
->
constr
->
num_defval
>
0
)
{
AttrDefault
*
attrdef
=
tupdesc
->
constr
->
defval
;
for
(
i
=
tupdesc
->
constr
->
num_defval
-
1
;
i
>=
0
;
i
--
)
{
if
(
attrdef
[
i
].
adbin
)
pfree
(
attrdef
[
i
].
adbin
);
if
(
attrdef
[
i
].
adsrc
)
pfree
(
attrdef
[
i
].
adsrc
);
}
pfree
(
attrdef
);
}
if
(
tupdesc
->
constr
->
num_check
>
0
)
{
ConstrCheck
*
check
=
tupdesc
->
constr
->
check
;
for
(
i
=
tupdesc
->
constr
->
num_check
-
1
;
i
>=
0
;
i
--
)
{
if
(
check
[
i
].
ccname
)
pfree
(
check
[
i
].
ccname
);
if
(
check
[
i
].
ccbin
)
pfree
(
check
[
i
].
ccbin
);
if
(
check
[
i
].
ccsrc
)
pfree
(
check
[
i
].
ccsrc
);
}
pfree
(
check
);
}
pfree
(
tupdesc
->
constr
);
}
pfree
(
tupdesc
);
}
/* ----------------------------------------------------------------
/* ----------------------------------------------------------------
* TupleDescInitEntry
* TupleDescInitEntry
*
*
...
@@ -179,7 +292,7 @@ TupleDescInitEntry(TupleDesc desc,
...
@@ -179,7 +292,7 @@ TupleDescInitEntry(TupleDesc desc,
memset
(
att
->
attname
.
data
,
0
,
NAMEDATALEN
);
memset
(
att
->
attname
.
data
,
0
,
NAMEDATALEN
);
att
->
attdisbursion
=
0
;
/* dummy value */
att
->
attdisbursion
=
0
;
/* dummy value */
att
->
attcacheoff
=
-
1
;
att
->
attcacheoff
=
-
1
;
att
->
attnum
=
attributeNumber
;
att
->
attnum
=
attributeNumber
;
...
@@ -318,9 +431,12 @@ BuildDescForRelation(List *schema, char *relname)
...
@@ -318,9 +431,12 @@ BuildDescForRelation(List *schema, char *relname)
AttrNumber
attnum
;
AttrNumber
attnum
;
List
*
p
;
List
*
p
;
TupleDesc
desc
;
TupleDesc
desc
;
char
*
attname
;
AttrDefault
*
attrdef
=
NULL
;
char
*
typename
;
TupleConstr
*
constr
=
(
TupleConstr
*
)
palloc
(
sizeof
(
TupleConstr
));
char
*
attname
;
char
*
typename
;
int
attdim
;
int
attdim
;
int
ndef
=
0
;
bool
attisset
;
bool
attisset
;
/* ----------------
/* ----------------
...
@@ -329,6 +445,7 @@ BuildDescForRelation(List *schema, char *relname)
...
@@ -329,6 +445,7 @@ BuildDescForRelation(List *schema, char *relname)
*/
*/
natts
=
length
(
schema
);
natts
=
length
(
schema
);
desc
=
CreateTemplateTupleDesc
(
natts
);
desc
=
CreateTemplateTupleDesc
(
natts
);
constr
->
has_not_null
=
false
;
attnum
=
0
;
attnum
=
0
;
...
@@ -385,14 +502,44 @@ BuildDescForRelation(List *schema, char *relname)
...
@@ -385,14 +502,44 @@ BuildDescForRelation(List *schema, char *relname)
}
}
/* This is for constraints */
/* This is for constraints */
if
(
entry
->
is_not_null
)
{
if
(
entry
->
is_not_null
)
if
(
!
desc
->
constr
)
constr
->
has_not_null
=
true
;
desc
->
constr
=
(
TupleConstr
*
)
palloc
(
sizeof
(
TupleConstr
));
desc
->
constr
->
has_not_null
=
true
;
}
desc
->
attrs
[
attnum
-
1
]
->
attnotnull
=
entry
->
is_not_null
;
desc
->
attrs
[
attnum
-
1
]
->
attnotnull
=
entry
->
is_not_null
;
if
(
entry
->
defval
!=
NULL
)
{
if
(
attrdef
==
NULL
)
attrdef
=
(
AttrDefault
*
)
palloc
(
natts
*
sizeof
(
AttrDefault
));
attrdef
[
ndef
].
adnum
=
attnum
;
attrdef
[
ndef
].
adbin
=
NULL
;
attrdef
[
ndef
].
adsrc
=
entry
->
defval
;
ndef
++
;
desc
->
attrs
[
attnum
-
1
]
->
atthasdef
=
true
;
}
}
}
if
(
constr
->
has_not_null
||
ndef
>
0
)
{
desc
->
constr
=
constr
;
if
(
ndef
>
0
)
/* DEFAULTs */
{
if
(
ndef
<
natts
)
constr
->
defval
=
(
AttrDefault
*
)
repalloc
(
attrdef
,
ndef
*
sizeof
(
AttrDefault
));
else
constr
->
defval
=
attrdef
;
constr
->
num_defval
=
ndef
;
}
else
constr
->
num_defval
=
0
;
constr
->
num_check
=
0
;
}
else
{
pfree
(
constr
);
desc
->
constr
=
NULL
;
}
return
desc
;
return
desc
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment