Search in sources :

Example 16 with IndexRowGenerator

use of org.apache.derby.iapi.sql.dictionary.IndexRowGenerator in project derby by apache.

the class FromBaseTable method isOneRowResultSet.

/**
 * Is this a one-row result set with the given conglomerate descriptor?
 */
private boolean isOneRowResultSet(ConglomerateDescriptor cd, OptimizablePredicateList predList) throws StandardException {
    if (predList == null) {
        return false;
    }
    if (SanityManager.DEBUG) {
        if (!(predList instanceof PredicateList)) {
            SanityManager.THROWASSERT("predList should be a PredicateList, but is a " + predList.getClass().getName());
        }
    }
    PredicateList restrictList = (PredicateList) predList;
    if (!cd.isIndex()) {
        return false;
    }
    IndexRowGenerator irg = cd.getIndexDescriptor();
    // is this a unique index
    if (!irg.isUnique()) {
        return false;
    }
    int[] baseColumnPositions = irg.baseColumnPositions();
    // Do we have an exact match on the full key
    for (int index = 0; index < baseColumnPositions.length; index++) {
        // get the column number at this position
        int curCol = baseColumnPositions[index];
        /* Is there a pushable equality predicate on this key column?
			 * (IS NULL is also acceptable)
			 */
        if (!restrictList.hasOptimizableEqualityPredicate(this, curCol, true)) {
            return false;
        }
    }
    return true;
}
Also used : IndexRowGenerator(org.apache.derby.iapi.sql.dictionary.IndexRowGenerator) OptimizablePredicateList(org.apache.derby.iapi.sql.compile.OptimizablePredicateList)

Example 17 with IndexRowGenerator

use of org.apache.derby.iapi.sql.dictionary.IndexRowGenerator in project derby by apache.

the class SYSCONGLOMERATESRowFactory method buildDescriptor.

// /////////////////////////////////////////////////////////////////////////
// 
// ABSTRACT METHODS TO BE IMPLEMENTED BY CHILDREN OF CatalogRowFactory
// 
// /////////////////////////////////////////////////////////////////////////
/**
 * @param row a SYSCOLUMNS row
 * @param parentTupleDescriptor	Null for this kind of descriptor.
 * @param dd dataDictionary
 *
 * @return	a conglomerate descriptor equivalent to a SYSCONGOMERATES row
 *
 * @exception   StandardException thrown on failure
 */
public TupleDescriptor buildDescriptor(ExecRow row, TupleDescriptor parentTupleDescriptor, DataDictionary dd) throws StandardException {
    if (SanityManager.DEBUG)
        SanityManager.ASSERT(row.nColumns() == SYSCONGLOMERATES_COLUMN_COUNT, "Wrong number of columns for a SYSCONGLOMERATES row");
    DataDescriptorGenerator ddg = dd.getDataDescriptorGenerator();
    long conglomerateNumber;
    String name;
    boolean isConstraint;
    boolean isIndex;
    IndexRowGenerator indexRowGenerator;
    DataValueDescriptor col;
    ConglomerateDescriptor conglomerateDesc;
    String conglomUUIDString;
    UUID conglomUUID;
    String schemaUUIDString;
    UUID schemaUUID;
    String tableUUIDString;
    UUID tableUUID;
    /* 1st column is SCHEMAID (UUID - char(36)) */
    col = row.getColumn(1);
    schemaUUIDString = col.getString();
    schemaUUID = getUUIDFactory().recreateUUID(schemaUUIDString);
    /* 2nd column is TABLEID (UUID - char(36)) */
    col = row.getColumn(2);
    tableUUIDString = col.getString();
    tableUUID = getUUIDFactory().recreateUUID(tableUUIDString);
    /* 3nd column is CONGLOMERATENUMBER (long) */
    col = row.getColumn(3);
    conglomerateNumber = col.getLong();
    /* 4rd column is CONGLOMERATENAME (varchar(128)) */
    col = row.getColumn(4);
    name = col.getString();
    /* 5th column is ISINDEX (boolean) */
    col = row.getColumn(5);
    isIndex = col.getBoolean();
    /* 6th column is DESCRIPTOR */
    col = row.getColumn(6);
    indexRowGenerator = new IndexRowGenerator((IndexDescriptor) col.getObject());
    /* 7th column is ISCONSTRAINT (boolean) */
    col = row.getColumn(7);
    isConstraint = col.getBoolean();
    /* 8th column is CONGLOMERATEID (UUID - char(36)) */
    col = row.getColumn(8);
    conglomUUIDString = col.getString();
    conglomUUID = getUUIDFactory().recreateUUID(conglomUUIDString);
    /* now build and return the descriptor */
    conglomerateDesc = ddg.newConglomerateDescriptor(conglomerateNumber, name, isIndex, indexRowGenerator, isConstraint, conglomUUID, tableUUID, schemaUUID);
    return conglomerateDesc;
}
Also used : DataDescriptorGenerator(org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator) IndexRowGenerator(org.apache.derby.iapi.sql.dictionary.IndexRowGenerator) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) UUID(org.apache.derby.catalog.UUID) IndexDescriptor(org.apache.derby.catalog.IndexDescriptor) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)

Example 18 with IndexRowGenerator

use of org.apache.derby.iapi.sql.dictionary.IndexRowGenerator in project derby by apache.

the class SYSCONGLOMERATESRowFactory method makeRow.

/**
 * Make a SYSCONGLOMERATES row
 *
 * @return	Row suitable for inserting into SYSCONGLOMERATES.
 *
 * @exception   StandardException thrown on failure
 */
public ExecRow makeRow(TupleDescriptor td, TupleDescriptor parent) throws StandardException {
    ExecRow row;
    DataValueDescriptor col;
    String tabID = null;
    Long conglomNumber = null;
    String conglomName = null;
    Boolean supportsIndex = null;
    IndexRowGenerator indexRowGenerator = null;
    Boolean supportsConstraint = null;
    String conglomUUIDString = null;
    String schemaID = null;
    ConglomerateDescriptor conglomerate = (ConglomerateDescriptor) td;
    if (td != null) {
        /* Sometimes the SchemaDescriptor is non-null and sometimes it
			 * is null.  (We can't just rely on getting the schema id from 
			 * the ConglomerateDescriptor because it can be null when
			 * we are creating a new conglomerate.
			 */
        if (parent != null) {
            SchemaDescriptor sd = (SchemaDescriptor) parent;
            schemaID = sd.getUUID().toString();
        } else {
            schemaID = conglomerate.getSchemaID().toString();
        }
        tabID = conglomerate.getTableID().toString();
        conglomNumber = conglomerate.getConglomerateNumber();
        conglomName = conglomerate.getConglomerateName();
        conglomUUIDString = conglomerate.getUUID().toString();
        supportsIndex = conglomerate.isIndex();
        indexRowGenerator = conglomerate.getIndexDescriptor();
        supportsConstraint = conglomerate.isConstraint();
    }
    /* RESOLVE - It would be nice to require less knowledge about sysconglomerates
		 * and have this be more table driven.
		 */
    /* Build the row to insert */
    row = getExecutionFactory().getValueRow(SYSCONGLOMERATES_COLUMN_COUNT);
    /* 1st column is SCHEMAID (UUID - char(36)) */
    row.setColumn(1, new SQLChar(schemaID));
    /* 2nd column is TABLEID (UUID - char(36)) */
    row.setColumn(2, new SQLChar(tabID));
    /* 3rd column is CONGLOMERATENUMBER (long) */
    row.setColumn(3, new SQLLongint(conglomNumber));
    /* 4th column is CONGLOMERATENAME (varchar(128)) 
		** If null, use the tableid so we always
		** have a unique column
		*/
    row.setColumn(4, (conglomName == null) ? new SQLVarchar(tabID) : new SQLVarchar(conglomName));
    /* 5th  column is ISINDEX (boolean) */
    row.setColumn(5, new SQLBoolean(supportsIndex));
    /* 6th column is DESCRIPTOR
		*  (user type org.apache.derby.catalog.IndexDescriptor)
		*/
    row.setColumn(6, new UserType((indexRowGenerator == null ? (IndexDescriptor) null : indexRowGenerator.getIndexDescriptor())));
    /* 7th column is ISCONSTRAINT (boolean) */
    row.setColumn(7, new SQLBoolean(supportsConstraint));
    /* 8th column is CONGLOMERATEID (UUID - char(36)) */
    row.setColumn(8, new SQLChar(conglomUUIDString));
    return row;
}
Also used : SchemaDescriptor(org.apache.derby.iapi.sql.dictionary.SchemaDescriptor) SQLChar(org.apache.derby.iapi.types.SQLChar) SQLVarchar(org.apache.derby.iapi.types.SQLVarchar) IndexDescriptor(org.apache.derby.catalog.IndexDescriptor) ConglomerateDescriptor(org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor) IndexRowGenerator(org.apache.derby.iapi.sql.dictionary.IndexRowGenerator) SQLLongint(org.apache.derby.iapi.types.SQLLongint) ExecRow(org.apache.derby.iapi.sql.execute.ExecRow) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean) UserType(org.apache.derby.iapi.types.UserType) SQLBoolean(org.apache.derby.iapi.types.SQLBoolean)

Aggregations

IndexRowGenerator (org.apache.derby.iapi.sql.dictionary.IndexRowGenerator)18 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)10 Properties (java.util.Properties)5 UUID (org.apache.derby.catalog.UUID)5 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)5 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)5 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)4 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)4 IndexDescriptor (org.apache.derby.catalog.IndexDescriptor)3 SortObserver (org.apache.derby.iapi.store.access.SortObserver)3 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)3 RowLocation (org.apache.derby.iapi.types.RowLocation)3 LanguageProperties (org.apache.derby.iapi.sql.LanguageProperties)2 AccessPath (org.apache.derby.iapi.sql.compile.AccessPath)2 OptimizablePredicateList (org.apache.derby.iapi.sql.compile.OptimizablePredicateList)2 DataDescriptorGenerator (org.apache.derby.iapi.sql.dictionary.DataDescriptorGenerator)2 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)2 SchemaDescriptor (org.apache.derby.iapi.sql.dictionary.SchemaDescriptor)2 StatisticsDescriptor (org.apache.derby.iapi.sql.dictionary.StatisticsDescriptor)2