Maintaining join information at global context
The IP can implement any join optimization by maintaining details of the tables in a join, in a global query context.
#define MAX_JOIN_SIZE 10
typedef __IP_GSTMT_DA {
int iJoinSize;
char pJoinTableName[MAX_JOIN_SIZE][32];
};
Uint16 iValue;
int iValueLen;
int iJoinSize, iProcessOrder;
iRetCode = dam_getInfo(NULL, pStmtDA->dam_hstmt,
DAM_INFO_JOIN_QUERY_SIZE, (void *)&iValue, sizeof(iValue), &iValueLen);
iJoinSize = iValue;
iRetCode = dam_getInfo(NULL, pStmtDA->dam_hstmt,
DAM_INFO_QUERY_PROCESS_ORDER, (void *)&iValue, sizeof(iValue), &iValueLen);
iProcessOrder = iValue;
if (iProcessOrder == 0) {
IP_GSTMT_DA *pgStmtDA;
/* allocate global IP context and return it to OpenAccess SDK SQL engine */
pgStmtDA = (IP_GSTMT_DA *)xm_allocItem(pStmtDA->pMemTree,
sizeof(IP_GSTMT_DA), XM_NOFLAGS);
iRetCode = dam_setInfo(NULL,
pStmtDA->dam_hstmt,
DAM_INFO_STMT_IP_CONTEXT, (void *)pgStmtDA, 0);
/* save table names of each table in join */
pgStmtDA->iJoinSize = iJoinSize;
iProcessOrder = 0;
while (iProcessOrder < iJoinSize) {
iRetCode = dam_describeJoinTable(pStmtDA->dam_hstmt, iProcessOrder, NULL, NULL,
pgStmtDA->pJoinTableName[iProcessOrder], NULL, NULL);
if (iRetCode != DAM_SUCCESS) break;
iProcessOrder++;
}
/* first table in Join */
else {
IP_GSTMT_DA *pgStmtDA;
int iValueLen;
iRetCode = dam_getInfo(NULL, pStmtDA->dam_hstmt,
DAM_INFO_STMT_IP_CONTEXT, (void *)&pgStmtDA, sizeof(pgStmtDA), &iValueLen);
}