Search in sources :

Example 61 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method storeCost.

/**
 * Test the access level StoreCost interface.
 * <p>
 *
 * @return true if the test succeeded.
 *
 * @param tc The transaction controller to use in the test.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail Unexpected behaviour from the API
 */
protected boolean storeCost(TransactionController tc) throws StandardException, T_Fail {
    int key_value;
    REPORT("(storeCost) starting");
    // Create a heap conglomerate.
    T_AccessRow template_row = new T_AccessRow(2);
    long conglomid = tc.createConglomerate(// create a heap conglomerate
    "heap", // 1 column template.
    template_row.getRowArray(), // column sort order not required for heap
    null, // default collation
    null, // default properties
    null, // not temporary
    TransactionController.IS_DEFAULT);
    // Open the conglomerate.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a 2 column row.
    T_AccessRow r1 = new T_AccessRow(2);
    SQLInteger c1 = new SQLInteger(1);
    SQLInteger c2 = new SQLInteger(100);
    r1.setCol(0, c1);
    r1.setCol(1, c2);
    // Get a location template
    RowLocation rowloc1 = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc1);
    cc.close();
    tc.commit();
    // flush the cache to get the row count updated.
    flush_cache();
    // Test 1 - ASSERT(initial row count after 1 insert should be 1)
    StoreCostController scc = tc.openStoreCost(conglomid);
    if (scc.getEstimatedRowCount() != 1) {
        throw T_Fail.testFailMsg("(storeCost) estimated row count not 1:" + scc.getEstimatedRowCount());
    }
    // Test 2 - ASSERT(should be able to set arbitrary row count)
    scc.setEstimatedRowCount(5);
    if (scc.getEstimatedRowCount() != 5) {
        throw T_Fail.testFailMsg("(storeCost) estimated row count not 5");
    }
    scc.setEstimatedRowCount(1);
    // Test 3 - ASSERT(should implement getFetchFromRowLocationCost())
    // should figure out some way to determine reasonable number is
    // returned.
    double fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) null, 0);
    fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) new FormatableBitSet(0), 0);
    REPORT("fetch cost (full row) of row loc = " + fetch_cost);
    fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) new FormatableBitSet(1), 0);
    FormatableBitSet bit_set = new FormatableBitSet(2);
    REPORT("fetch cost (no cols) of row loc = " + fetch_cost);
    bit_set.set(1);
    fetch_cost = scc.getFetchFromRowLocationCost((FormatableBitSet) new FormatableBitSet(1), 0);
    REPORT("fetch cost (1 col) of row loc = " + fetch_cost);
    // Test 4 - ASSERT(should implement getFetchFromFullKeyCost())
    // should figure out some way to determine reasonable number is
    // returned.
    /* - RESOLVE HEAP does not implement this.
        fetch_cost = 
            scc.getFetchFromFullKeyCost((FormatableBitSet) null, (int[]) null, 0);
        REPORT("fetch full key cost (full row) of row loc = " + fetch_cost);

        fetch_cost = 
            scc.getFetchFromFullKeyCost(
                (FormatableBitSet) new FormatableBitSet(0), (int[]) null, 0);
        REPORT("fetch full key cost (no cols) of row loc = " + fetch_cost);

        fetch_cost = 
            scc.getFetchFromFullKeyCost(
                (FormatableBitSet) new FormatableBitSet(1), (int[]) null, 0);
        REPORT("fetch full key cost (no cols) of row loc = " + fetch_cost);

        bit_set = new FormatableBitSet(2);
        bit_set.set(1);
        fetch_cost = 
            scc.getFetchFromFullKeyCost(
                (FormatableBitSet) new FormatableBitSet(1), (int[]) null, 0);
        REPORT("fetch full key cost (1 col) of row loc = " + fetch_cost);
        */
    // Test 5 - ASSERT(should implement getScanCost())
    // should figure out some way to determine reasonable number is
    // returned.
    StoreCostResult cost_result = new T_StoreCostResult();
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    (FormatableBitSet) null, // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (full row) of row loc = " + cost_result);
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    new FormatableBitSet(0), // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (no cols) of row loc = " + cost_result);
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    new FormatableBitSet(1), // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (no cols) of row loc = " + cost_result);
    bit_set = new FormatableBitSet(2);
    bit_set.set(1);
    scc.getScanCost(StoreCostController.STORECOST_SCAN_NORMAL, // row count
    -1, // number of rows fetched at a time from access.
    1, // forUpdate
    false, // validColumns
    bit_set, // template
    new T_AccessRow(2).getRowArray(), // start position - first row in conglomerate
    null, // unused if start position is null.
    0, // stop position - last row in conglomerate
    null, // unused if stop position is null.
    0, // reopen_scan?
    false, // access_type
    0, // cost result.
    cost_result);
    REPORT("fetch scan cost (1 cols) of row loc = " + cost_result);
    // make sure you can get a row location.
    rowloc1 = scc.newRowLocationTemplate();
    REPORT("(storeCost) finishing");
    return true;
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 62 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method insertAndUpdate.

// Insert a single row with a single column containing
// the first argument integer, update it to the second
// value, and make sure the update happened.
// 
protected boolean insertAndUpdate(TransactionController tc, long conglomid, int value1, int value2) throws StandardException, T_Fail {
    // Open the conglomerate.
    ConglomerateController cc = tc.openConglomerate(conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_AccessRow r1 = new T_AccessRow(1);
    r1.setCol(0, new SQLInteger(value1));
    // Get a location template
    RowLocation rowloc = cc.newRowLocationTemplate();
    // Insert the row and remember its location.
    cc.insertAndFetchLocation(r1.getRowArray(), rowloc);
    // Update it to the second value
    DataValueDescriptor[] update_row = new DataValueDescriptor[1];
    update_row[0] = new SQLInteger(value2);
    FormatableBitSet update_desc = new FormatableBitSet(1);
    update_desc.set(0);
    cc.replace(rowloc, update_row, update_desc);
    // Create a new row (of the same type, since the interface expects
    // the callers to be keeping the row types straight.
    T_AccessRow r2 = new T_AccessRow(1);
    SQLInteger c2 = new SQLInteger(0);
    r2.setCol(0, c2);
    // Fetch the stored value.
    if (!cc.fetch(rowloc, r2.getRowArray(), (FormatableBitSet) null)) {
        throw T_Fail.testFailMsg("(insertAndUpdate) Fetch val not there.");
    }
    // Close the conglomerate.
    cc.close();
    // Make sure we read back the value we wrote.
    if (c2.getInt() != value2)
        throw T_Fail.testFailMsg("(insertAndUpdate) Fetch value != updated value.");
    else
        return true;
}
Also used : FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLInteger(org.apache.derby.iapi.types.SQLInteger)

Example 63 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_AccessFactory method getBtreeTemplate.

private DataValueDescriptor[] getBtreeTemplate(TransactionController tc, long baseConglomId) throws StandardException {
    // Open a scan on the base conglomerate which will return all rows.
    FormatableBitSet singleColumn = new FormatableBitSet(1);
    singleColumn.set(0);
    ScanController sc = tc.openScan(baseConglomId, false, // not for update
    0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, // all columns, all as objects
    singleColumn, null, 0, null, null, 0);
    // Create the template for the index. This method "knows" that
    // all rows in the base table have one IntCol
    T_AccessRow template = new T_AccessRow(2);
    SQLLongint col0 = new SQLLongint(0);
    RowLocation col1 = sc.newRowLocationTemplate();
    template.setCol(0, col0);
    template.setCol(1, col1);
    sc.close();
    return (template.getRowArray());
}
Also used : SQLLongint(org.apache.derby.iapi.types.SQLLongint) FormatableBitSet(org.apache.derby.iapi.services.io.FormatableBitSet) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 64 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_QualifierTest method t_testqual.

/* public methods of T_QualifierTest */
public boolean t_testqual(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    DataValueDescriptor[] openscan_template = null;
    DataValueDescriptor[] fetch_template = null;
    DataValueDescriptor[] base_row = null;
    T_SecondaryIndexRow index_row = null;
    long value = -1;
    long[] col1 = { 1, 3, 4, 4, 4, 5, 5, 5, 6, 7, 9 };
    long[] col2 = { 1, 1, 2, 4, 6, 2, 4, 6, 1, 1, 1 };
    long[] col3 = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
    long conglomid;
    long base_conglomid;
    long index_conglomid;
    ConglomerateController base_cc = null;
    ConglomerateController index_cc = null;
    RowLocation base_rowloc = null;
    base_row = TemplateRow.newU8Row(3);
    if (init_conglomerate_type.compareTo("BTREE") == 0) {
        base_conglomid = tc.createConglomerate("heap", base_row, null, null, null, TransactionController.IS_DEFAULT);
        index_row = new T_SecondaryIndexRow();
        base_cc = tc.openConglomerate(base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        base_rowloc = base_cc.newRowLocationTemplate();
        index_row.init(base_row, base_rowloc, 4);
        index_conglomid = tc.createConglomerate(init_conglomerate_type, index_row.getRow(), null, null, init_properties, init_temporary ? TransactionController.IS_TEMPORARY : TransactionController.IS_DEFAULT);
        index_cc = tc.openConglomerate(index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        conglomid = index_conglomid;
        openscan_template = index_row.getRow();
        // make another template
        T_SecondaryIndexRow fetch_index_row = new T_SecondaryIndexRow();
        fetch_index_row.init(TemplateRow.newU8Row(3), base_cc.newRowLocationTemplate(), 4);
        fetch_template = fetch_index_row.getRow();
    } else {
        base_conglomid = tc.createConglomerate(init_conglomerate_type, base_row, // default order
        null, // default collation
        null, init_properties, init_temporary ? TransactionController.IS_TEMPORARY : TransactionController.IS_DEFAULT);
        base_cc = tc.openConglomerate(base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
        base_rowloc = base_cc.newRowLocationTemplate();
        conglomid = base_conglomid;
        openscan_template = base_row;
        fetch_template = TemplateRow.newU8Row(3);
    }
    // insert them in reverse order just to make sure btree is sorting them
    for (int i = col1.length - 1; i >= 0; i--) {
        ((SQLLongint) (base_row[0])).setValue(col1[i]);
        ((SQLLongint) (base_row[1])).setValue(col2[i]);
        ((SQLLongint) (base_row[2])).setValue(col3[i]);
        base_cc.insertAndFetchLocation(base_row, base_rowloc);
        if (init_conglomerate_type.compareTo("BTREE") == 0) {
            index_cc.insert(index_row.getRow());
        }
    }
    tc.commit();
    // run through a predicates as described in the openScan() interface,
    // and implement them in qualifiers rather than start and stop.
    // 
    // Use the following SQLLongint's for qualifier values //
    SQLLongint qual_col1 = new SQLLongint(-1);
    SQLLongint qual_col2 = new SQLLongint(-1);
    SQLLongint qual_col3 = new SQLLongint(-1);
    SQLLongint qual_col4 = new SQLLongint(-1);
    SQLLongint qual_col5 = new SQLLongint(-1);
    SQLLongint qual_col6 = new SQLLongint(-1);
    SQLLongint qual_col7 = new SQLLongint(-1);
    // test predicate x = 5
    // 
    // result set should be: {5,2,16}, {5,4,17}, {5,6,18}
    // 
    progress("qual scan (x = 5)");
    qual_col1.setValue(5);
    Qualifier[][] q1 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q1, null, ScanController.NA, 3, 16, init_order)) {
        ret_val = false;
    }
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x > 5 |{5}  |GT |null |   |{6,1} .. {9,1}|{5,6} .. {9,1} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x > 5)");
    qual_col1.setValue(5);
    Qualifier[][] q2 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSOREQUALS, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q2, null, ScanController.NA, 3, 19, init_order)) {
        ret_val = false;
    }
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x >= 5|{5}  |GE |null |   |{5,2} .. {9,1}|{4,6} .. {9,1} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x >= 5)");
    qual_col1.setValue(5);
    Qualifier[][] q3 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q3, null, ScanController.NA, 6, 16, init_order)) {
        ret_val = false;
    }
    // 
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x <= 5|null |   |{5}  |GT |{1,1} .. {5,6}|first .. {5,6} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x <= 5)");
    qual_col1.setValue(5);
    Qualifier[][] q4 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSOREQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q4, null, ScanController.NA, 8, 11, init_order)) {
        ret_val = false;
    }
    // 
    // +---------------------------------------------------------+
    // |pred  |start|key|stop |key|rows returned |rows locked    |
    // |      |value|op |value|op |              |(serialization)|
    // +------+-----+---+-----+---+--------------+---------------+
    // |x < 5 |null |   |{5}  |GE |{1,1} .. {4,6}|first .. {4,6} |
    // +-----------------------------------------+---------------+
    progress("qual scan (x < 5)");
    qual_col1.setValue(5);
    Qualifier[][] q5 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q5, null, ScanController.NA, 5, 11, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x >= 5 and x <= 7|{5},  |GE|{7}  |GT|{5,2} .. {7,1}|{4,6} .. {7,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x >= 5 and x <= 7)");
    qual_col1.setValue(5);
    qual_col2.setValue(7);
    Qualifier[][] q6 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, true, true, true), new QualifierUtil(0, qual_col2, Orderable.ORDER_OP_LESSOREQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q6, null, ScanController.NA, 5, 16, init_order)) {
        ret_val = false;
    }
    // passing qualifier in q6[0][0], q6[0][1] should evaluate same as
    // passing in q6[0][0], q6[1][0]
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x >= 5 and x <= 7|{5},  |GE|{7}  |GT|{5,2} .. {7,1}|{4,6} .. {7,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x >= 5 and x <= 7)");
    qual_col1.setValue(5);
    qual_col2.setValue(7);
    Qualifier[][] q6_2 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_LESSTHAN, true, true, true) }, { new QualifierUtil(0, qual_col2, Orderable.ORDER_OP_LESSOREQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q6_2, null, ScanController.NA, 5, 16, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 5 and y > 2  |{5,2} |GT|{5}  |GT|{5,4} .. {5,6}|{5,2} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 5 and y > 2)");
    qual_col1.setValue(5);
    qual_col2.setValue(2);
    Qualifier[][] q7 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true), new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_LESSOREQUALS, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q7, null, ScanController.NA, 2, 17, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 5 and y >= 2 | {5,2}|GE| {5} |GT|{5,2} .. {5,6}|{4,6} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 5 and y >= 2)");
    qual_col1.setValue(5);
    qual_col2.setValue(2);
    Qualifier[][] q8 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true), new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_LESSTHAN, true, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q8, null, ScanController.NA, 3, 16, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 5 and y < 5  | {5}  |GE|{5,5}|GE|{5,2} .. {5,4}|{4,6} .. {5,4}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 5 and y < 5)");
    qual_col1.setValue(5);
    qual_col2.setValue(5);
    Qualifier[][] q9 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true), new QualifierUtil(1, qual_col1, Orderable.ORDER_OP_LESSTHAN, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q9, null, ScanController.NA, 2, 16, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred             |start|key|stop |key|rows returned|rows locked   |
    // |                 |value|op |value|op |             |(serialized)  |
    // +-----------------+------+--+-----+--+--------------+--------------+
    // |x = 2            | {2}  |GE| {2} |GT|none          |{1,1} .. {1,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 2)");
    qual_col1.setValue(2);
    Qualifier[][] q10 = { { new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true) } };
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q10, null, ScanController.NA, 0, 0, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred            |start|key|stop |key|rows returned |rows locked   |
    // |                |value|op |value|op |              |(serialized)  |
    // +----------------+-----+---+-----+-- +--------------+--------------+
    // |x >= 5 or y = 6 | null|   | null|   |{4,6} .. {9,1}|{1,1} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x >= 5) or (y = 6)");
    qual_col1.setValue(5);
    qual_col2.setValue(6);
    Qualifier[][] q11 = new Qualifier[2][];
    q11[0] = new Qualifier[0];
    q11[1] = new Qualifier[2];
    q11[1][0] = new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_GREATEROREQUALS, false, true, true);
    q11[1][1] = new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_EQUALS, false, true, true);
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q11, null, ScanController.NA, 7, 15, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred            |start|key|stop |key|rows returned |rows locked   |
    // |                |value|op |value|op |              |(serialized)  |
    // +----------------+-----+---+-----+-- +--------------+--------------+
    // |(x = 1 or y = 1 or y = 6)|
    // |     and        |
    // |(x > 5 or y = 1)|
    // |     and        |
    // |(x = 9 or x = 7)|null |   | null|   |{7,1} .. {9,1}|{1,1} .. {9,1}|
    // +------------------------------------------------------------------+
    progress("qual scan (x = 1 or y = 1 or y = 6) and (x > 5 or y = 1) and (x = 9 or x = 7)");
    qual_col1.setValue(1);
    qual_col2.setValue(1);
    qual_col3.setValue(6);
    qual_col4.setValue(5);
    qual_col5.setValue(1);
    qual_col6.setValue(9);
    qual_col7.setValue(7);
    Qualifier[][] q12 = new Qualifier[4][];
    q12[0] = new Qualifier[0];
    q12[1] = new Qualifier[3];
    q12[2] = new Qualifier[2];
    q12[3] = new Qualifier[2];
    q12[1][0] = new QualifierUtil(0, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[1][1] = new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[1][2] = new QualifierUtil(1, qual_col3, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[2][0] = new QualifierUtil(0, qual_col4, Orderable.ORDER_OP_GREATERTHAN, false, true, true);
    q12[2][1] = new QualifierUtil(1, qual_col5, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[3][0] = new QualifierUtil(0, qual_col6, Orderable.ORDER_OP_EQUALS, false, true, true);
    q12[3][1] = new QualifierUtil(0, qual_col7, Orderable.ORDER_OP_EQUALS, false, true, true);
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q12, null, ScanController.NA, 2, 20, init_order)) {
        ret_val = false;
    }
    // +------------------------------------------------------------------+
    // |pred            |start|key|stop |key|rows returned |rows locked   |
    // |                |value|op |value|op |              |(serialized)  |
    // +----------------+-----+---+-----+-- +--------------+--------------+
    // |(y = 4 or y = 1)|
    // |     and        |
    // |(x = 1 or x = 4 or x= 9)|
    // |     and        |
    // |(z = 15 or z = 14)|null |   | null|   |{4,4} .. {4,4}| ALL        |
    // +------------------------------------------------------------------+
    progress("qual scan (x = 1 or x = 4 or x= 9) and (y = 4 or y = 1) and (z = 15 or z = 14)");
    qual_col1.setValue(4);
    qual_col2.setValue(1);
    qual_col3.setValue(1);
    qual_col4.setValue(4);
    qual_col5.setValue(9);
    qual_col6.setValue(15);
    qual_col7.setValue(14);
    Qualifier[][] q13 = new Qualifier[4][];
    q13[0] = new Qualifier[0];
    q13[1] = new Qualifier[2];
    q13[2] = new Qualifier[3];
    q13[3] = new Qualifier[2];
    q13[1][0] = new QualifierUtil(1, qual_col1, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[1][1] = new QualifierUtil(1, qual_col2, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[2][0] = new QualifierUtil(0, qual_col4, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[2][1] = new QualifierUtil(0, qual_col5, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[2][2] = new QualifierUtil(0, qual_col3, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[3][0] = new QualifierUtil(2, qual_col6, Orderable.ORDER_OP_EQUALS, false, true, true);
    q13[3][1] = new QualifierUtil(2, qual_col7, Orderable.ORDER_OP_EQUALS, false, true, true);
    if (!t_scan(tc, conglomid, openscan_template, fetch_template, null, ScanController.NA, q13, null, ScanController.NA, 1, 14, init_order)) {
        ret_val = false;
    }
    tc.commit();
    progress("Ending t_testqual");
    return (ret_val);
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLLongint(org.apache.derby.iapi.types.SQLLongint) Qualifier(org.apache.derby.iapi.store.access.Qualifier) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation)

Example 65 with RowLocation

use of org.apache.derby.iapi.types.RowLocation in project derby by apache.

the class T_CreateConglomRet method t_012.

/**
 * Test Special cases of split.
 * <p>
 * Testing: restartSplitFor() call in BranchControlRow().
 *
 * The second case is the same as the first except the calling code is
 * trying to split a branch page and the parent branch page doesn't have
 * room for the row.
 *
 * @exception  StandardException  Standard exception policy.
 * @exception  T_Fail  Throws T_Fail on any test failure.
 */
protected boolean t_012(TransactionController tc) throws StandardException, T_Fail {
    boolean ret_val = true;
    REPORT("Starting t_011");
    T_CreateConglomRet create_ret = new T_CreateConglomRet();
    createCongloms(tc, 2, false, true, 0, create_ret);
    // Open the base conglomerate.
    ConglomerateController base_cc = tc.openConglomerate(create_ret.base_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Open the index conglomerate.
    ConglomerateController index_cc = tc.openConglomerate(create_ret.index_conglomid, false, TransactionController.OPENMODE_FORUPDATE, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE);
    // Create a row.
    T_SecondaryIndexRow index_row = new T_SecondaryIndexRow();
    RowLocation rowloc = base_cc.newRowLocationTemplate();
    DataValueDescriptor[] base_row = TemplateRow.newU8Row(2);
    base_row[0] = new SQLChar("aaaaaaaaaa");
    index_row.init(base_row, rowloc, 3);
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 1000));
    ((SQLLongint) base_row[1]).setValue(1);
    base_cc.insertAndFetchLocation(base_row, rowloc);
    // CAUSE BRANCH splitFor to loop:
    // pick numbers so that split will happen in middle of page.  Do this
    // by first inserting last row in table and then insert smaller rows,
    // then insert rows before it until the table is just ready to split
    // the root, and finally insert some shorter rows in such a way as
    // they cause a split but the split point is chosen with one of the
    // larger rows as the descriminator causing 1st splitfor pass to fail
    // and loop back and do a splitFor the larger row.
    // insert enough rows so the tree is 3 levels, just ready to go to
    // 4 levels.
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("ma", 500));
    for (int i = 0; i < 3; i++) {
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("m", 1000));
    for (int i = 3; i < 23; i++) {
        ((SQLLongint) base_row[1]).setValue(i);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    ((SQLChar) base_row[0]).setValue(T_b2i.repeatString("a", 600));
    for (int i = 123; i > 111; i--) {
        ((SQLLongint) base_row[1]).setValue(i * 2);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    {
        ((SQLLongint) base_row[1]).setValue(227);
        base_cc.insertAndFetchLocation(base_row, rowloc);
        if (index_cc.insert(index_row.getRow()) != 0)
            throw T_Fail.testFailMsg("insert failed");
    }
    // ((B2IController)index_cc).printTree();
    tc.commit();
    // Close the conglomerate.
    index_cc.close();
    REPORT("Ending t_012");
    return (ret_val);
}
Also used : ConglomerateController(org.apache.derby.iapi.store.access.ConglomerateController) SQLLongint(org.apache.derby.iapi.types.SQLLongint) SQLChar(org.apache.derby.iapi.types.SQLChar) DataValueDescriptor(org.apache.derby.iapi.types.DataValueDescriptor) RowLocation(org.apache.derby.iapi.types.RowLocation) SQLLongint(org.apache.derby.iapi.types.SQLLongint)

Aggregations

RowLocation (org.apache.derby.iapi.types.RowLocation)89 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)54 ConglomerateController (org.apache.derby.iapi.store.access.ConglomerateController)40 SQLLongint (org.apache.derby.iapi.types.SQLLongint)35 FormatableBitSet (org.apache.derby.iapi.services.io.FormatableBitSet)32 ScanController (org.apache.derby.iapi.store.access.ScanController)29 ExecRow (org.apache.derby.iapi.sql.execute.ExecRow)27 Properties (java.util.Properties)16 SQLInteger (org.apache.derby.iapi.types.SQLInteger)13 ExecIndexRow (org.apache.derby.iapi.sql.execute.ExecIndexRow)12 StandardException (org.apache.derby.shared.common.error.StandardException)11 SQLChar (org.apache.derby.iapi.types.SQLChar)10 ColumnDescriptor (org.apache.derby.iapi.sql.dictionary.ColumnDescriptor)7 TransactionController (org.apache.derby.iapi.store.access.TransactionController)7 ConglomerateDescriptor (org.apache.derby.iapi.sql.dictionary.ConglomerateDescriptor)6 ConstraintDescriptor (org.apache.derby.iapi.sql.dictionary.ConstraintDescriptor)4 ColumnOrdering (org.apache.derby.iapi.store.access.ColumnOrdering)4 UUID (org.apache.derby.catalog.UUID)3 ContextManager (org.apache.derby.iapi.services.context.ContextManager)3 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)3