Package org.hsqldb_voltpatches.index

Examples of org.hsqldb_voltpatches.index.Index


     * tables
     */
    Index getIndexForColumns(OrderedIntHashSet set) {

        int   maxMatchCount = 0;
        Index selected      = null;

        if (set.isEmpty()) {
            return null;
        }

        for (int i = 0, count = indexList.length; i < count; i++) {
            Index currentindex = getIndex(i);
            int[] indexcols    = currentindex.getColumns();
            int   matchCount   = set.getOrderedMatchCount(indexcols);

            if (matchCount == 0) {
                continue;
            }
View Full Code Here


    }

    // A VoltDB extension to support indexed expressions
    public final Index createAndAddExprIndexStructure(HsqlName name, int[] columns, Expression[] indexExprs, boolean unique, boolean constraint) {

        Index newExprIndex = createIndexStructure(name, columns, null, null, unique, constraint, false);
        newExprIndex = newExprIndex.withExpressions(indexExprs);
        addIndex(newExprIndex);
        return newExprIndex;
    } /* createAndAddExprIndexStructure */
 
View Full Code Here

                    indexName = session.database.nameManager.newAutoName("IDX",
                            c.getName().name, table.getSchemaName(),
                            table.getName(), SchemaObject.INDEX);

                    // A VoltDB extension to support indexed expressions and the assume unique attribute
                    Index index = null;
                    if (c.indexExprs != null) {
                        // Special case handling for VoltDB indexed expressions
                        index = table.createAndAddExprIndexStructure(indexName, c.core.mainCols, c.indexExprs, true, true).setAssumeUnique(c.assumeUnique);
                    } else {
                        index = table.createAndAddIndexStructure(indexName,
View Full Code Here

        c.setColumnsIndexes(table);

        Constraint uniqueConstraint =
            c.core.mainTable.getUniqueConstraintForColumns(c.core.mainCols,
                c.core.refCols);
        Index      mainIndex  = uniqueConstraint.getMainIndex();
        TableWorks tableWorks = new TableWorks(session, table);

        tableWorks.checkCreateForeignKey(c);

        boolean isForward = c.core.mainTable.getSchemaName()
                            != table.getSchemaName();
        int offset = session.database.schemaManager.getTableIndex(table);

        if (offset != -1
                && offset
                   < session.database.schemaManager.getTableIndex(
                       c.core.mainTable)) {
            isForward = true;
        }

        HsqlName refIndexName = session.database.nameManager.newAutoName("IDX",
            table.getSchemaName(), table.getName(), SchemaObject.INDEX);
        Index index = table.createAndAddIndexStructure(refIndexName,
            c.core.refCols, null, null, false, true, isForward);
        HsqlName mainName = session.database.nameManager.newAutoName("REF",
            c.getName().name, table.getSchemaName(), table.getName(),
            SchemaObject.INDEX);
View Full Code Here

                    break;
                }
                case OpTypes.EQUAL :
                    if (e.exprSubType == OpTypes.ANY_QUANTIFIED) {
                        Index index = rangeVar.rangeTable.getIndexForColumn(
                            e.getLeftNode().nodes[0].getColumnIndex());

// code to disable IN optimisation
//                        index = null;
                        if (index != null
                                && inExpressions[rangeVarIndex] == null) {
                            inExpressions[rangeVarIndex] = e;

                            inExpressionCount++;
                        } else {
                            rangeVar.addCondition(e, isJoin);
                        }

                        exprList.set(j, null);

                        continue;
                    }

                // $FALL-THROUGH$
                case OpTypes.IS_NULL : {
                    int colIndex = e.getLeftNode().getColumnIndex();

                    colIndexSetEqual.add(colIndex);

                    break;
                }
                case OpTypes.NOT : {
                    int colIndex =
                        e.getLeftNode().getLeftNode().getColumnIndex();

                    colIndexSetOther.add(colIndex);

                    break;
                }
            }
        }

        boolean isEqual = true;
        Index   idx = rangeVar.rangeTable.getIndexForColumns(colIndexSetEqual);

        if (idx == null) {
            isEqual = false;
            idx     = rangeVar.rangeTable.getIndexForColumns(colIndexSetOther);
        }

        // different procedure for subquery tables
        if (idx == null && rangeVar.rangeTable.isSessionBased) {
            if (!colIndexSetEqual.isEmpty()) {
                int[] cols = colIndexSetEqual.toArray();

                idx = rangeVar.rangeTable.getIndexForColumns(cols);
            }

            if (idx == null && !colIndexSetOther.isEmpty()) {
                int[] cols = colIndexSetOther.toArray();

                idx = rangeVar.rangeTable.getIndexForColumns(cols);
            }
        }

        // no index found
        if (idx == null) {
            for (int j = 0, size = exprList.size(); j < size; j++) {
                Expression e = (Expression) exprList.get(j);

                if (e != null) {
                    rangeVar.addCondition(e, isJoin);
                }
            }

            return;
        }

        // index found
        int[] cols     = idx.getColumns();
        int   colCount = cols.length;

        if (isEqual && colCount > 1) {
            Expression[] firstRowExpressions = new Expression[cols.length];
View Full Code Here

        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 =
View Full Code Here

        rowIdMap.clear();
    }

    public void setAccessor(Index key, CachedObject accessor) {

        Index index = (Index) key;

        accessorList[index.getPosition()] = accessor;
    }
View Full Code Here

        manager.setStore(table, null);
    }

    public void setAccessor(Index key, CachedObject accessor) {

        Index index = (Index) key;

        accessorList[index.getPosition()] = accessor;
    }
View Full Code Here

     * checks all rows of a table to ensure they all have a corresponding
     * row in the main table.
     */
    void checkReferencedRows(Session session, Table table, int[] rowColArray) {

        Index           mainIndex = getMainIndex();
        PersistentStore store     = session.sessionData.getRowStore(table);
        RowIterator     it        = table.rowIterator(session);

        while (true) {
            Row row = it.getNextRow();

            if (row == null) {
                break;
            }

            Object[] rowData = row.getData();

            if (ArrayUtil.hasNull(rowData, rowColArray)) {
                if (core.matchType == OpTypes.MATCH_SIMPLE) {
                    continue;
                }
            } else if (mainIndex.exists(session, store, rowData,
                                        rowColArray)) {
                continue;
            }

            if (ArrayUtil.hasAllNull(rowData, rowColArray)) {
View Full Code Here

    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
View Full Code Here

TOP

Related Classes of org.hsqldb_voltpatches.index.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.