Difference between revisions of "Postgres Dev."
(→Test Environment) |
(→Current Efforts) |
||
Line 12: | Line 12: | ||
*Prints out the name of the relation. This function is called directly in the printf of the error message in ri_triggers.c | *Prints out the name of the relation. This function is called directly in the printf of the error message in ri_triggers.c | ||
− | <pre> | + | <pre>relation->rd_rel->relnamespace</pre> |
*There's a member variable: relnamespace in Form_pg_class data type. | *There's a member variable: relnamespace in Form_pg_class data type. | ||
− | It is of type id0, | + | It is of type id0, representing a unique namespace identifier. I just replaced the appearance of RelationGetRelationName(relation) with relation->rd_red->relnamespace and when the error occurs this number is printed. |
− | |||
*Error "violates foreign key constraint located in: | *Error "violates foreign key constraint located in: | ||
Line 21: | Line 20: | ||
postgresql-8.3.7/src/backend/utils/adt/ri_triggers.c: | postgresql-8.3.7/src/backend/utils/adt/ri_triggers.c: | ||
</pre> | </pre> | ||
+ | |||
+ | ri_triggers.c houses all cases where fk constraints fail. There are 5 or 6 variations. The primary error message is the same in each case, and a detail section gets more specific about why the constraint blocked the SQL action. | ||
== Test Environment == | == Test Environment == |
Revision as of 20:57, 20 April 2009
Postgres Internals Notes
Current Efforts
- Declaration of RelationGetRelationNamespace:
postgresql-8.3.7/src/include/utils/rel.h
RelationGetRelationName(relation)
- Prints out the name of the relation. This function is called directly in the printf of the error message in ri_triggers.c
relation->rd_rel->relnamespace
- There's a member variable: relnamespace in Form_pg_class data type.
It is of type id0, representing a unique namespace identifier. I just replaced the appearance of RelationGetRelationName(relation) with relation->rd_red->relnamespace and when the error occurs this number is printed.
- Error "violates foreign key constraint located in:
postgresql-8.3.7/src/backend/utils/adt/ri_triggers.c:
ri_triggers.c houses all cases where fk constraints fail. There are 5 or 6 variations. The primary error message is the same in each case, and a detail section gets more specific about why the constraint blocked the SQL action.
Test Environment
We are currently creating a test environment on db-devel.cs.earlham.edu where a query causes a foreign key constraint. I created a simpler case, with a single relation. When I query
SELECT * FROM (wrong relation name)
An error gets returned, and only the relation name is reported. Our fix plans to address this case, however searching for error messages containing "does not exist" yielded too many result to be useful.
I was able to locate the error messages generated by foreign key constraints. They come from one file, called ri_triggers.c
We have created a local test environment and accompanying script that fails on a fk constraint. When the SQL call fails, our modified error message gets printed with the namespace identification number in place of the relation name.
Open Questions
- What's the difference between a tablespace and a namespace? - addressed
- Is there a way to take a namespace identifier and get a namespace object?