Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
Postgres FD Implementation
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Abuhujair Javed
Postgres FD Implementation
Commits
d40885cc
Commit
d40885cc
authored
Aug 22, 1997
by
Vadim B. Mikheev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ ExecConstraints()
parent
faebf2f8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
133 additions
and
43 deletions
+133
-43
src/backend/executor/execMain.c
src/backend/executor/execMain.c
+133
-43
No files found.
src/backend/executor/execMain.c
View file @
d40885cc
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
*
*
*
*
* IDENTIFICATION
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.1
8 1997/08/22 03:12:16
vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.1
9 1997/08/22 14:28:20
vadim Exp $
*
*
*-------------------------------------------------------------------------
*-------------------------------------------------------------------------
*/
*/
...
@@ -73,8 +73,6 @@ static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid,
...
@@ -73,8 +73,6 @@ static void ExecDelete(TupleTableSlot *slot, ItemPointer tupleid,
static
void
ExecReplace
(
TupleTableSlot
*
slot
,
ItemPointer
tupleid
,
static
void
ExecReplace
(
TupleTableSlot
*
slot
,
ItemPointer
tupleid
,
EState
*
estate
,
Query
*
parseTree
);
EState
*
estate
,
Query
*
parseTree
);
static
HeapTuple
ExecAttrDefault
(
Relation
rel
,
HeapTuple
tuple
);
/* end of local decls */
/* end of local decls */
#ifdef QUERY_LIMIT
#ifdef QUERY_LIMIT
...
@@ -930,29 +928,15 @@ ExecAppend(TupleTableSlot *slot,
...
@@ -930,29 +928,15 @@ ExecAppend(TupleTableSlot *slot,
if
(
resultRelationDesc
->
rd_att
->
constr
)
if
(
resultRelationDesc
->
rd_att
->
constr
)
{
{
if
(
resultRelationDesc
->
rd_att
->
constr
->
num_defval
>
0
)
HeapTuple
newtuple
;
{
HeapTuple
newtuple
;
newtuple
=
ExecConstraints
(
"ExecAppend"
,
resultRelationDesc
,
tuple
);
newtuple
=
ExecAttrDefault
(
resultRelationDesc
,
tuple
);
if
(
newtuple
!=
tuple
)
/* modified by DEFAULT */
if
(
newtuple
!=
tuple
)
{
Assert
(
slot
->
ttc_shouldFree
);
slot
->
val
=
tuple
=
newtuple
;
}
}
if
(
resultRelationDesc
->
rd_att
->
constr
->
has_not_null
)
{
{
int
attrChk
;
Assert
(
slot
->
ttc_shouldFree
);
pfree
(
tuple
);
for
(
attrChk
=
1
;
attrChk
<=
resultRelationDesc
->
rd_att
->
natts
;
attrChk
++
)
slot
->
val
=
tuple
=
newtuple
;
{
if
(
resultRelationDesc
->
rd_att
->
attrs
[
attrChk
-
1
]
->
attnotnull
&&
heap_attisnull
(
tuple
,
attrChk
))
elog
(
WARN
,
"ExecAppend: Fail to add null value in not null attribute %s"
,
resultRelationDesc
->
rd_att
->
attrs
[
attrChk
-
1
]
->
attname
.
data
);
}
}
}
}
}
...
@@ -1081,15 +1065,19 @@ ExecReplace(TupleTableSlot *slot,
...
@@ -1081,15 +1065,19 @@ ExecReplace(TupleTableSlot *slot,
* ----------------
* ----------------
*/
*/
if
(
resultRelationDesc
->
rd_att
->
constr
&&
resultRelationDesc
->
rd_att
->
constr
->
has_not_null
)
if
(
resultRelationDesc
->
rd_att
->
constr
)
{
{
int
attrChk
;
HeapTuple
newtuple
;
for
(
attrChk
=
1
;
attrChk
<=
resultRelationDesc
->
rd_att
->
natts
;
attrChk
++
)
{
if
(
resultRelationDesc
->
rd_att
->
attrs
[
attrChk
-
1
]
->
attnotnull
&&
heap_attisnull
(
tuple
,
attrChk
))
newtuple
=
ExecConstraints
(
"ExecReplace"
,
resultRelationDesc
,
tuple
);
elog
(
WARN
,
"ExecReplace: Fail to update null value in not null attribute %s"
,
resultRelationDesc
->
rd_att
->
attrs
[
attrChk
-
1
]
->
attname
.
data
);
if
(
newtuple
!=
tuple
)
/* modified by DEFAULT */
}
{
}
Assert
(
slot
->
ttc_shouldFree
);
pfree
(
tuple
);
slot
->
val
=
tuple
=
newtuple
;
}
}
/* ----------------
/* ----------------
* replace the heap tuple
* replace the heap tuple
...
@@ -1140,7 +1128,8 @@ ExecAttrDefault (Relation rel, HeapTuple tuple)
...
@@ -1140,7 +1128,8 @@ ExecAttrDefault (Relation rel, HeapTuple tuple)
{
{
int
ndef
=
rel
->
rd_att
->
constr
->
num_defval
;
int
ndef
=
rel
->
rd_att
->
constr
->
num_defval
;
AttrDefault
*
attrdef
=
rel
->
rd_att
->
constr
->
defval
;
AttrDefault
*
attrdef
=
rel
->
rd_att
->
constr
->
defval
;
ExprContext
*
econtext
=
makeNode
(
ExprContext
);
ExprContext
*
econtext
=
makeNode
(
ExprContext
);
HeapTuple
newtuple
;
Node
*
expr
;
Node
*
expr
;
bool
isnull
;
bool
isnull
;
bool
isdone
;
bool
isdone
;
...
@@ -1150,21 +1139,23 @@ ExecAttrDefault (Relation rel, HeapTuple tuple)
...
@@ -1150,21 +1139,23 @@ ExecAttrDefault (Relation rel, HeapTuple tuple)
char
*
repl
=
NULL
;
char
*
repl
=
NULL
;
int
i
;
int
i
;
econtext
->
ecxt_scantuple
=
NULL
;
/* scan tuple slot */
econtext
->
ecxt_innertuple
=
NULL
;
/* inner tuple slot */
econtext
->
ecxt_outertuple
=
NULL
;
/* outer tuple slot */
econtext
->
ecxt_relation
=
NULL
;
/* relation */
econtext
->
ecxt_relid
=
0
;
/* relid */
econtext
->
ecxt_param_list_info
=
NULL
;
/* param list info */
econtext
->
ecxt_range_table
=
NULL
;
/* range table */
for
(
i
=
0
;
i
<
ndef
;
i
++
)
for
(
i
=
0
;
i
<
ndef
;
i
++
)
{
{
if
(
!
heap_attisnull
(
tuple
,
attrdef
[
i
].
adnum
)
)
if
(
!
heap_attisnull
(
tuple
,
attrdef
[
i
].
adnum
)
)
continue
;
continue
;
expr
=
(
Node
*
)
stringToNode
(
attrdef
[
i
].
adbin
);
expr
=
(
Node
*
)
stringToNode
(
attrdef
[
i
].
adbin
);
econtext
->
ecxt_scantuple
=
NULL
;
/* scan tuple slot */
econtext
->
ecxt_innertuple
=
NULL
;
/* inner tuple slot */
econtext
->
ecxt_outertuple
=
NULL
;
/* outer tuple slot */
econtext
->
ecxt_relation
=
NULL
;
/* relation */
econtext
->
ecxt_relid
=
0
;
/* relid */
econtext
->
ecxt_param_list_info
=
NULL
;
/* param list info */
econtext
->
ecxt_range_table
=
NULL
;
/* range table */
val
=
ExecEvalExpr
(
expr
,
econtext
,
&
isnull
,
&
isdone
);
val
=
ExecEvalExpr
(
expr
,
econtext
,
&
isnull
,
&
isdone
);
pfree
(
expr
);
if
(
isnull
)
if
(
isnull
)
continue
;
continue
;
...
@@ -1182,9 +1173,108 @@ ExecAttrDefault (Relation rel, HeapTuple tuple)
...
@@ -1182,9 +1173,108 @@ ExecAttrDefault (Relation rel, HeapTuple tuple)
}
}
pfree
(
econtext
);
if
(
repl
==
NULL
)
if
(
repl
==
NULL
)
return
(
tuple
);
return
(
tuple
);
return
(
heap_modifytuple
(
tuple
,
InvalidBuffer
,
rel
,
replValue
,
replNull
,
repl
));
newtuple
=
heap_modifytuple
(
tuple
,
InvalidBuffer
,
rel
,
replValue
,
replNull
,
repl
);
pfree
(
repl
);
pfree
(
replNull
);
pfree
(
replValue
);
return
(
newtuple
);
}
static
char
*
ExecRelCheck
(
Relation
rel
,
HeapTuple
tuple
)
{
int
ncheck
=
rel
->
rd_att
->
constr
->
num_check
;
ConstrCheck
*
check
=
rel
->
rd_att
->
constr
->
check
;
ExprContext
*
econtext
=
makeNode
(
ExprContext
);
TupleTableSlot
*
slot
=
makeNode
(
TupleTableSlot
);
RangeTblEntry
*
rte
=
makeNode
(
RangeTblEntry
);
List
*
rtlist
;
List
*
qual
;
bool
res
;
int
i
;
slot
->
val
=
tuple
;
slot
->
ttc_shouldFree
=
false
;
slot
->
ttc_descIsNew
=
true
;
slot
->
ttc_tupleDescriptor
=
rel
->
rd_att
;
slot
->
ttc_buffer
=
InvalidBuffer
;
slot
->
ttc_whichplan
=
-
1
;
rte
->
relname
=
nameout
(
&
(
rel
->
rd_rel
->
relname
));
rte
->
timeRange
=
NULL
;
rte
->
refname
=
rte
->
relname
;
rte
->
relid
=
rel
->
rd_id
;
rte
->
inh
=
false
;
rte
->
archive
=
false
;
rte
->
inFromCl
=
true
;
rte
->
timeQual
=
NULL
;
rtlist
=
lcons
(
rte
,
NIL
);
econtext
->
ecxt_scantuple
=
slot
;
/* scan tuple slot */
econtext
->
ecxt_innertuple
=
NULL
;
/* inner tuple slot */
econtext
->
ecxt_outertuple
=
NULL
;
/* outer tuple slot */
econtext
->
ecxt_relation
=
rel
;
/* relation */
econtext
->
ecxt_relid
=
0
;
/* relid */
econtext
->
ecxt_param_list_info
=
NULL
;
/* param list info */
econtext
->
ecxt_range_table
=
rtlist
;
/* range table */
for
(
i
=
0
;
i
<
ncheck
;
i
++
)
{
qual
=
(
List
*
)
stringToNode
(
check
[
i
].
ccbin
);
res
=
ExecQual
(
qual
,
econtext
);
pfree
(
qual
);
if
(
!
res
)
return
(
check
[
i
].
ccname
);
}
pfree
(
slot
);
pfree
(
rte
->
relname
);
pfree
(
rte
);
pfree
(
rtlist
);
pfree
(
econtext
);
return
((
char
*
)
NULL
);
}
HeapTuple
ExecConstraints
(
char
*
caller
,
Relation
rel
,
HeapTuple
tuple
)
{
HeapTuple
newtuple
=
tuple
;
Assert
(
rel
->
rd_att
->
constr
);
if
(
rel
->
rd_att
->
constr
->
num_defval
>
0
)
newtuple
=
tuple
=
ExecAttrDefault
(
rel
,
tuple
);
if
(
rel
->
rd_att
->
constr
->
has_not_null
)
{
int
attrChk
;
for
(
attrChk
=
1
;
attrChk
<=
rel
->
rd_att
->
natts
;
attrChk
++
)
{
if
(
rel
->
rd_att
->
attrs
[
attrChk
-
1
]
->
attnotnull
&&
heap_attisnull
(
tuple
,
attrChk
))
elog
(
WARN
,
"%s: Fail to add null value in not null attribute %s"
,
caller
,
rel
->
rd_att
->
attrs
[
attrChk
-
1
]
->
attname
.
data
);
}
}
if
(
rel
->
rd_att
->
constr
->
num_check
>
0
)
{
char
*
failed
;
if
(
(
failed
=
ExecRelCheck
(
rel
,
tuple
)
)
!=
NULL
)
elog
(
WARN
,
"%s: rejected due to CHECK constraint %s"
,
caller
,
failed
);
}
return
(
newtuple
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment