Search in sources :

Example 1 with Index

use of org.hsqldb_voltpatches.index.Index in project voltdb by VoltDB.

the class ExpressionLogical method getAllAnyValue.

/** @todo - null value in rows */
private Boolean getAllAnyValue(Session session, Object[] data, SubQuery subquery) {
    Table table = subquery.getTable();
    boolean empty = table.isEmpty(session);
    Index index = table.getFullIndex();
    RowIterator it;
    Row firstrow;
    PersistentStore store = session.sessionData.getRowStore(table);
    Row lastrow = index.lastRow(session, store);
    Object[] lastdata;
    Object[] firstdata;
    switch(exprSubType) {
        case OpTypes.ANY_QUANTIFIED:
            {
                if (empty) {
                    return Boolean.FALSE;
                }
                if (countNulls(data) == data.length) {
                    return null;
                }
                lastdata = lastrow.getData();
                if (countNulls(lastdata) == data.length) {
                    return null;
                }
                convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
                if (opType == OpTypes.EQUAL) {
                    it = index.findFirstRow(session, store, data);
                    return it.hasNext() ? Boolean.TRUE : Boolean.FALSE;
                }
                it = index.findFirstRowNotNull(session, store);
                firstrow = it.getNextRow();
                firstdata = firstrow.getData();
                Boolean comparefirst = compareValues(session, data, firstdata);
                Boolean comparelast = compareValues(session, data, lastdata);
                switch(opType) {
                    case OpTypes.NOT_EQUAL:
                        return Boolean.TRUE.equals(comparefirst) || Boolean.TRUE.equals(comparelast) ? Boolean.TRUE : Boolean.FALSE;
                    case OpTypes.GREATER:
                        return comparefirst;
                    case OpTypes.GREATER_EQUAL:
                        return comparefirst;
                    case OpTypes.SMALLER:
                        return comparelast;
                    case OpTypes.SMALLER_EQUAL:
                        return comparelast;
                }
                break;
            }
        case OpTypes.ALL_QUANTIFIED:
            {
                if (empty) {
                    return Boolean.TRUE;
                }
                if (countNulls(data) == data.length) {
                    return null;
                }
                it = index.firstRow(session, store);
                firstrow = it.getNextRow();
                firstdata = firstrow.getData();
                if (countNulls(firstdata) == data.length) {
                    return null;
                }
                convertToType(session, data, nodes[LEFT].nodeDataTypes, nodes[RIGHT].nodeDataTypes);
                it = index.findFirstRow(session, store, data);
                if (opType == OpTypes.EQUAL) {
                    if (it.hasNext()) {
                        return subquery.getTable().getRowCount(store) == 1 ? Boolean.TRUE : Boolean.FALSE;
                    } else {
                        return Boolean.FALSE;
                    }
                }
                if (opType == OpTypes.NOT_EQUAL) {
                    return it.hasNext() ? Boolean.FALSE : Boolean.TRUE;
                }
                lastdata = lastrow.getData();
                Boolean comparefirst = compareValues(session, data, firstdata);
                Boolean comparelast = compareValues(session, data, lastdata);
                switch(opType) {
                    case OpTypes.GREATER:
                        return comparelast;
                    case OpTypes.GREATER_EQUAL:
                        return comparelast;
                    case OpTypes.SMALLER:
                        return comparefirst;
                    case OpTypes.SMALLER_EQUAL:
                        return comparefirst;
                }
                break;
            }
    }
    return null;
}
Also used : RowIterator(org.hsqldb_voltpatches.navigator.RowIterator) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Index(org.hsqldb_voltpatches.index.Index)

Example 2 with Index

use of org.hsqldb_voltpatches.index.Index in project voltdb by VoltDB.

the class RangeVariable method describe.

/**
     * Retreives a String representation of this obejct. <p>
     *
     * The returned String describes this object's table, alias
     * access mode, index, join mode, Start, End and And conditions.
     *
     * @return a String representation of this object
     */
public String describe(Session session) {
    StringBuffer sb;
    String temp;
    Index index;
    Index primaryIndex;
    int[] primaryKey;
    boolean hidden;
    boolean fullScan;
    sb = new StringBuffer();
    index = rangeIndex;
    primaryIndex = rangeTable.getPrimaryIndex();
    primaryKey = rangeTable.getPrimaryKey();
    hidden = false;
    fullScan = (indexCondition == null && indexEndCondition == null);
    if (index == null) {
        index = primaryIndex;
    }
    if (index == primaryIndex && primaryKey.length == 0) {
        hidden = true;
        fullScan = true;
    }
    sb.append(super.toString()).append('\n');
    sb.append("table=[").append(rangeTable.getName().name).append("]\n");
    if (tableAlias != null) {
        sb.append("alias=[").append(tableAlias.name).append("]\n");
    }
    sb.append("access=[").append(fullScan ? "FULL SCAN" : "INDEX PRED").append("]\n");
    sb.append("index=[");
    sb.append(index == null ? "NONE" : index.getName() == null ? "UNNAMED" : index.getName().name);
    sb.append(hidden ? "[HIDDEN]]\n" : "]\n");
    temp = "INNER";
    if (isLeftJoin) {
        temp = "LEFT OUTER";
        if (isRightJoin) {
            temp = "FULL";
        }
    } else if (isRightJoin) {
        temp = "RIGHT OUTER";
    }
    sb.append("joinType=[").append(temp).append("]\n");
    temp = indexCondition == null ? "null" : indexCondition.describe(session);
    if (findFirstExpressions != null) {
        StringBuffer sbt = new StringBuffer();
        for (int i = 0; i < multiColumnCount; i++) {
            sbt.append(findFirstExpressions[i].describe(session));
        }
        temp = sbt.toString();
    }
    sb.append("eStart=[").append(temp).append("]\n");
    temp = indexEndCondition == null ? "null" : indexEndCondition.describe(session);
    sb.append("eEnd=[").append(temp).append("]\n");
    temp = nonIndexJoinCondition == null ? "null" : nonIndexJoinCondition.describe(session);
    sb.append("eAnd=[").append(temp).append("]");
    return sb.toString();
}
Also used : Index(org.hsqldb_voltpatches.index.Index)

Example 3 with Index

use of org.hsqldb_voltpatches.index.Index in project voltdb by VoltDB.

the class RangeVariable method voltGetRangeVariableXML.

/************************* Volt DB Extensions *************************/
/**
     * VoltDB added method to get a non-catalog-dependent
     * representation of this HSQLDB object.
     * @param session The current Session object may be needed to resolve
     * some names.
     * @return XML, correctly indented, representing this object.
     * @throws HSQLParseException
     */
VoltXMLElement voltGetRangeVariableXML(Session session) throws org.hsqldb_voltpatches.HSQLInterface.HSQLParseException {
    Index index;
    Index primaryIndex;
    index = rangeIndex;
    primaryIndex = rangeTable.getPrimaryIndex();
    // note: ignored if scan if full table scan
    if (index == null)
        index = primaryIndex;
    // output open tag
    VoltXMLElement scan = new VoltXMLElement("tablescan");
    if (rangeTable.tableType == TableBase.SYSTEM_SUBQUERY) {
        if (rangeTable instanceof TableDerived) {
            if (tableAlias == null || tableAlias.name == null) {
                // VoltDB require derived sub select table with user specified alias
                throw new org.hsqldb_voltpatches.HSQLInterface.HSQLParseException("SQL Syntax error: Every derived table must have its own alias.");
            }
            scan.attributes.put("table", tableAlias.name.toUpperCase());
            VoltXMLElement subQuery = ((TableDerived) rangeTable).dataExpression.voltGetXML(session);
            scan.children.add(subQuery);
        }
    } else {
        scan.attributes.put("table", rangeTable.getName().name.toUpperCase());
    }
    if (tableAlias != null && !rangeTable.getName().name.equals(tableAlias)) {
        scan.attributes.put("tablealias", tableAlias.name.toUpperCase());
    }
    // note if this is an outer join
    if (isLeftJoin && isRightJoin) {
        scan.attributes.put("jointype", "full");
    } else if (isLeftJoin) {
        scan.attributes.put("jointype", "left");
    } else if (isRightJoin) {
        scan.attributes.put("jointype", "right");
    } else {
        scan.attributes.put("jointype", "inner");
    }
    Expression joinCond = null;
    Expression whereCond = null;
    // else if indexCondition is set then it is where condition
    if (isJoinIndex == true) {
        joinCond = indexCondition;
        if (indexEndCondition != null) {
            joinCond = makeConjunction(joinCond, indexEndCondition);
        }
        // then go to the nonIndexJoinCondition
        if (nonIndexJoinCondition != null) {
            joinCond = makeConjunction(joinCond, nonIndexJoinCondition);
        }
        // then go to the nonIndexWhereCondition
        whereCond = nonIndexWhereCondition;
    } else {
        joinCond = nonIndexJoinCondition;
        whereCond = indexCondition;
        if (indexEndCondition != null) {
            whereCond = makeConjunction(whereCond, indexEndCondition);
        }
        // then go to the nonIndexWhereCondition
        if (nonIndexWhereCondition != null) {
            whereCond = makeConjunction(whereCond, nonIndexWhereCondition);
        }
    }
    if (joinCond != null) {
        joinCond = joinCond.eliminateDuplicates(session);
        VoltXMLElement joinCondEl = new VoltXMLElement("joincond");
        joinCondEl.children.add(joinCond.voltGetXML(session));
        scan.children.add(joinCondEl);
    }
    if (whereCond != null) {
        whereCond = whereCond.eliminateDuplicates(session);
        VoltXMLElement whereCondEl = new VoltXMLElement("wherecond");
        whereCondEl.children.add(whereCond.voltGetXML(session));
        scan.children.add(whereCondEl);
    }
    return scan;
}
Also used : Index(org.hsqldb_voltpatches.index.Index) HSQLParseException(org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)

Example 4 with Index

use of org.hsqldb_voltpatches.index.Index in project voltdb by VoltDB.

the class RangeVariableResolver method setInConditionsAsTables.

/**
     * Converts an IN conditions into a JOIN
     */
void setInConditionsAsTables() {
    for (int i = rangeVariables.length - 1; i >= 0; i--) {
        RangeVariable rangeVar = rangeVariables[i];
        Expression in = inExpressions[i];
        if (in != null) {
            Index index = rangeVar.rangeTable.getIndexForColumn(in.getLeftNode().nodes[0].getColumnIndex());
            RangeVariable newRangeVar = new RangeVariable(in.getRightNode().subQuery.getTable(), null, null, null, compileContext);
            RangeVariable[] newList = new RangeVariable[rangeVariables.length + 1];
            ArrayUtil.copyAdjustArray(rangeVariables, newList, newRangeVar, i, 1);
            rangeVariables = newList;
            // make two columns as arg
            ColumnSchema left = rangeVar.rangeTable.getColumn(in.getLeftNode().nodes[0].getColumnIndex());
            ColumnSchema right = newRangeVar.rangeTable.getColumn(0);
            Expression e = new ExpressionLogical(rangeVar, left, newRangeVar, right);
            rangeVar.addIndexCondition(e, index, flags[i]);
        }
    }
}
Also used : Index(org.hsqldb_voltpatches.index.Index)

Example 5 with Index

use of org.hsqldb_voltpatches.index.Index in project voltdb by VoltDB.

the class TableWorks method addExprIndex.

/************************* Volt DB Extensions *************************/
/**
     * A VoltDB extended variant of addIndex that supports indexed generalized non-column expressions.
     *
     * @param cols int[]
     * @param indexExprs Expression[]
     * @param name HsqlName
     * @param unique boolean
     * @param predicate Expression
     * @return new index
     */
Index addExprIndex(int[] col, Expression[] indexExprs, HsqlName name, boolean unique, Expression predicate) {
    Index newindex;
    if (table.isEmpty(session) || table.isIndexingMutable()) {
        newindex = table.createAndAddExprIndexStructure(name, col, indexExprs, unique, false);
    } else {
        newindex = table.createIndexStructure(name, col, null, null, unique, false, false).withExpressions(indexExprs);
        Table tn = table.moveDefinition(session, table.tableType, null, null, newindex, -1, 0, emptySet, emptySet);
        // for all sessions move the data
        tn.moveData(session, table, -1, 0);
        database.persistentStoreCollection.releaseStore(table);
        table = tn;
        setNewTableInSchema(table);
        updateConstraints(table, emptySet);
    }
    database.schemaManager.addSchemaObject(newindex);
    database.schemaManager.recompileDependentObjects(table);
    if (predicate != null) {
        newindex = newindex.withPredicate(predicate);
    }
    return newindex;
}
Also used : Index(org.hsqldb_voltpatches.index.Index)

Aggregations

Index (org.hsqldb_voltpatches.index.Index)29 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)6 RowIterator (org.hsqldb_voltpatches.navigator.RowIterator)4 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)3 IndexAVL (org.hsqldb_voltpatches.index.IndexAVL)2 HashMappedList (org.hsqldb_voltpatches.lib.HashMappedList)2 HashMap (java.util.HashMap)1 HSQLParseException (org.hsqldb_voltpatches.HSQLInterface.HSQLParseException)1 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)1 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)1 Type (org.hsqldb_voltpatches.types.Type)1