use of org.apache.derby.catalog.types.ReferencedColumnsDescriptorImpl in project derby by apache.
the class IndexToBaseRowNode method generate.
/**
* Generation of an IndexToBaseRowNode creates an
* IndexRowToBaseRowResultSet, which uses the RowLocation in the last
* column of an index row to get the row from the base conglomerate (heap).
*
* @param acb The ActivationClassBuilder for the class being built
* @param mb the method for the method to be built
*
* @exception StandardException Thrown on error
*/
@Override
void generate(ActivationClassBuilder acb, MethodBuilder mb) throws StandardException {
ValueNode restriction = null;
/*
** Get the next ResultSet #, so that we can number this ResultSetNode,
** its ResultColumnList and ResultSet.
*/
assignResultSetNumber();
// Get the CostEstimate info for the underlying scan
setCostEstimate(getFinalCostEstimate());
/* Put the predicates back into the tree */
if (restrictionList != null) {
restriction = restrictionList.restorePredicates();
/* Allow the restrictionList to get garbage collected now
* that we're done with it.
*/
restrictionList = null;
}
// for the restriction, we generate an exprFun
// that evaluates the expression of the clause
// against the current row of the child's result.
// if the restriction is empty, simply pass null
// to optimize for run time performance.
// generate the function and initializer:
// Note: Boolean lets us return nulls (boolean would not)
// private Boolean exprN()
// {
// return <<restriction.generate(ps)>>;
// }
// static Method exprN = method pointer to exprN;
int heapColRefItem = -1;
if (heapReferencedCols != null) {
heapColRefItem = acb.addItem(heapReferencedCols);
}
int allColRefItem = -1;
if (allReferencedCols != null) {
allColRefItem = acb.addItem(allReferencedCols);
}
int heapOnlyColRefItem = -1;
if (heapOnlyReferencedCols != null) {
heapOnlyColRefItem = acb.addItem(heapOnlyReferencedCols);
}
/* Create the ReferencedColumnsDescriptorImpl which tells which columns
* come from the index.
*/
int indexColMapItem = acb.addItem(new ReferencedColumnsDescriptorImpl(getIndexColMapping()));
long heapConglomNumber = baseCD.getConglomerateNumber();
StaticCompiledOpenConglomInfo scoci = getLanguageConnectionContext().getTransactionCompile().getStaticCompiledConglomInfo(heapConglomNumber);
acb.pushGetResultSetFactoryExpression(mb);
mb.push(heapConglomNumber);
mb.push(acb.addItem(scoci));
source.generate(acb, mb);
mb.upCast(ClassName.NoPutResultSet);
// Skip over the index columns that are propagated from the source
// result set, if there are such columns. We won't pass the SQL NULL
// wrappers down to store for those columns anyways, so no need to
// generate them in the row template.
// NOTE: We have to check for the case where indexReferencedCols is
// not null, but no bits are set. This can happen when we need to get
// all of the columns from the heap due to a check constraint.
boolean skipPropagatedCols = indexReferencedCols != null && indexReferencedCols.getNumBitsSet() != 0;
mb.push(acb.addItem(getResultColumns().buildRowTemplate(heapReferencedCols, skipPropagatedCols)));
mb.push(getResultSetNumber());
mb.push(source.getBaseTableName());
mb.push(heapColRefItem);
mb.push(allColRefItem);
mb.push(heapOnlyColRefItem);
mb.push(indexColMapItem);
// if there is no restriction, we just want to pass null.
if (restriction == null) {
mb.pushNull(ClassName.GeneratedMethod);
} else {
// this sets up the method and the static field.
// generates:
// Object userExprFun { }
MethodBuilder userExprFun = acb.newUserExprFun();
// restriction knows it is returning its value;
/* generates:
* return <restriction.generate(acb)>;
* and adds it to userExprFun
* NOTE: The explicit cast to DataValueDescriptor is required
* since the restriction may simply be a boolean column or subquery
* which returns a boolean. For example:
* where booleanColumn
*/
restriction.generate(acb, userExprFun);
userExprFun.methodReturn();
// we are done modifying userExprFun, complete it.
userExprFun.complete();
// restriction is used in the final result set as an access of the new static
// field holding a reference to this new method.
// generates:
// ActivationClass.userExprFun
// which is the static field that "points" to the userExprFun
// that evaluates the where clause.
acb.pushMethodReference(mb, userExprFun);
}
mb.push(forUpdate);
mb.push(getCostEstimate().rowCount());
mb.push(getCostEstimate().getEstimatedCost());
mb.push(source.getTableDescriptor().getNumberOfColumns());
mb.callMethod(VMOpcode.INVOKEINTERFACE, (String) null, "getIndexRowToBaseRowResultSet", ClassName.NoPutResultSet, 15);
/*
** Remember if this result set is the cursor target table, so we
** can know which table to use when doing positioned update and delete.
*/
if (cursorTargetTable) {
acb.rememberCursorTarget(mb);
}
}
Aggregations