Paul Stapersma - 2012-02-23

The posted code to resolve the bug does not allow MayBMS to determine if a view is uncertain or not. The code that I provided in this post resolved this issue. In summary, views are created in the same way as tables. Hence, the same information has to be provided by views as with tables. Therefore, (1) the ViewStmt-definition is extended, (2) the rewrite phase is extended to store uncertainty information in the view-statement, (3) this information is passed to the functions that create views.

=== ParseNodes.h ===
typedef struct ViewStmt
{
NodeTag type;
RangeVar *view; /* the view to be created */
List *aliases; /* target column names */
Node *query; /* the SELECT query */
bool replace; /* replace an existing view? */

/** ADDED */
/* Extend the ViewStmt to store its tabletype */
char tabletype;
/** ADDED */
} ViewStmt;

=== Rewrite.c ===
==== process(Node *parsetree) ====
/* Process the parse tree according to the its type */
switch (nodeTag(parsetree))
{
/** ADDED */
/* the function 'process_view' rewrites the select of a ViewStmt */
case T_ViewStmt:
return (Node *) process_view((ViewStmt *) parsetree);
break;
/** ADDED */

==== Define new function ====
/** ADDED */
static ViewStmt *process_view(ViewStmt *view);
/** ADDED */

/** ADDED */
static ViewStmt *
process_view(ViewStmt *view)
{
ViewStmt *result = view;
SelectStmt *smt;

/* Rewrite the views select-statement by which it is created */
smt = process_select(view->query);
result->query = smt;
/* Assign the tabletype of the select-statement to the view-statement. Note that this is not persistent */
result->tabletype = smt->tabletype;

return result;
}
/** ADDED */

=== view.c ===
==== DefineView(ViewStmt *stmt, const char *queryString)
/** REMOVED
viewOid = DefineVirtualRelation(view, viewParse->targetList,
stmt->replace); */
/** ADDED */
viewOid = DefineVirtualRelation(view, viewParse->targetList,
stmt->replace, stmt->tabletype);
/** ADDED */

/* Add a parameter 'tabletype' */
==== DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace, char tabletype) ====

createStmt->tablespacename = NULL;

/** ADDED */
/* Assign the tabletype of the VirtualRelation (the view) to the createStmt
createStmt->tabletype = tabletype;
/** ADDED */

return DefineRelation(createStmt, RELKIND_VIEW);