TEST_F(TableTupleTest, VolatileStandAloneTuple) { UniqueEngine engine = UniqueEngineBuilder().build(); // A schema with // - one fixed size column // - one inlined variable-length column // - one non-inlined variable-length column ScopedTupleSchema schema{Tools::buildSchema(VALUE_TYPE_BIGINT, std::make_pair(VALUE_TYPE_VARCHAR, 12), std::make_pair(VALUE_TYPE_VARCHAR, 256))}; StandAloneTupleStorage standAloneTuple{schema.get()}; TableTuple tuple = standAloneTuple.tuple(); Tools::setTupleValues(&tuple, int64_t(0), "foo", "foo bar"); // Stand alone tuples are similar to pool-backed tuples. ASSERT_TRUE(tuple.inlinedDataIsVolatile()); ASSERT_FALSE(tuple.nonInlinedDataIsVolatile()); NValue nv = tuple.getNValue(0); ASSERT_FALSE(nv.getVolatile()); nv = tuple.getNValue(1); ASSERT_TRUE(nv.getVolatile()); nv = tuple.getNValue(2); ASSERT_FALSE(nv.getVolatile()); }
TEST_F(TableTupleTest, VolatileTempTuplePersistent) { UniqueEngine engine = UniqueEngineBuilder().build(); // A schema with // - one fixed-length column // - one inlined variable-length column // - one non-inlined variable-length column TupleSchema *schema = Tools::buildSchema(VALUE_TYPE_BIGINT, std::make_pair(VALUE_TYPE_VARCHAR, 12), std::make_pair(VALUE_TYPE_VARCHAR, 256)); std::vector<std::string> columnNames{"id", "inlined", "noninlined"}; char signature[20]; std::unique_ptr<Table> table{TableFactory::getPersistentTable(0, "perstbl", schema, columnNames, signature)}; TableTuple tuple = table->tempTuple(); Tools::setTupleValues(&tuple, int64_t(0), "foo", "foo bar"); ASSERT_TRUE(tuple.inlinedDataIsVolatile()); ASSERT_FALSE(tuple.nonInlinedDataIsVolatile()); NValue nv = tuple.getNValue(0); ASSERT_FALSE(nv.getVolatile()); nv = tuple.getNValue(1); ASSERT_TRUE(nv.getVolatile()); nv = tuple.getNValue(2); ASSERT_FALSE(nv.getVolatile()); table->insertTuple(tuple); TableIterator it = table->iterator(); TableTuple iterTuple{schema}; while (it.next(iterTuple)) { // Regular, TupleBlock-backed tuples are never volatile. ASSERT_FALSE(iterTuple.inlinedDataIsVolatile()); ASSERT_FALSE(iterTuple.nonInlinedDataIsVolatile()); nv = iterTuple.getNValue(0); ASSERT_FALSE(nv.getVolatile()); nv = iterTuple.getNValue(1); ASSERT_FALSE(nv.getVolatile()); nv = iterTuple.getNValue(2); ASSERT_FALSE(nv.getVolatile()); } }
TEST_F(LargeTempTableTest, Basic) { UniqueEngine engine = UniqueEngineBuilder().build(); LargeTempTableBlockCache* lttBlockCache = ExecutorContext::getExecutorContext()->lttBlockCache(); TupleSchema* schema = Tools::buildSchema(VALUE_TYPE_BIGINT, VALUE_TYPE_DOUBLE, std::make_pair(VALUE_TYPE_VARCHAR, 15), std::make_pair(VALUE_TYPE_VARCHAR, 128)); std::vector<std::string> columnNames{ "pk", "val", "inline_text", "noninline_text" }; auto ltt = makeUniqueTable(TableFactory::buildLargeTempTable( "ltmp", schema, columnNames)); TableTuple tuple = ltt->tempTuple(); // Temp tuple for large temp tables is like the temp tuple for // normal temp tables and persistent tables: // - inlined, variable-length data is volatile // - non-inlined, variable-length data is in the temp string pool, // which is not volatile. ASSERT_TRUE(tuple.inlinedDataIsVolatile()); ASSERT_FALSE(tuple.nonInlinedDataIsVolatile()); std::vector<int64_t> pkVals{66, 67, 68}; std::vector<double> floatVals{3.14, 6.28, 7.77}; std::vector<std::string> inlineTextVals{"foo", "bar", "baz"}; std::vector<std::string> nonInlineTextVals{"ffoo", "bbar", "bbaz"}; ASSERT_EQ(0, lttBlockCache->numPinnedEntries()); for (int i = 0; i < pkVals.size(); ++i) { Tools::setTupleValues(&tuple, pkVals[i], floatVals[i], inlineTextVals[i], nonInlineTextVals[i]); ltt->insertTuple(tuple); } ASSERT_EQ(1, lttBlockCache->numPinnedEntries()); try { TableIterator it = ltt->iterator(); ASSERT_TRUE_WITH_MESSAGE(false, "Expected release of pinned block to fail"); } catch (const SerializableEEException &exc) { ASSERT_NE(std::string::npos, exc.message().find("Attempt to iterate over large temp table before finishInserts() is called")); } ltt->finishInserts(); // finishInserts is idempotent and may be called multiple times ltt->finishInserts(); try { Tools::setTupleValues(&tuple, int64_t(-1), 3.14, "dino", "ddino"); ltt->insertTuple(tuple); ASSERT_TRUE_WITH_MESSAGE(false, "Expected insertTuple() to fail after finishInserts() called"); } catch (const SerializableEEException& exc) { ASSERT_NE(std::string::npos, exc.message().find("Attempt to insert after finishInserts() called")); } ASSERT_EQ(0, lttBlockCache->numPinnedEntries()); { TableIterator iter = ltt->iterator(); TableTuple iterTuple(ltt->schema()); int i = 0; while (iter.next(iterTuple)) { if (! assertTupleValuesEqual(&iterTuple, pkVals[i], floatVals[i], inlineTextVals[i], nonInlineTextVals[i])) { break; } ++i; } ASSERT_EQ(pkVals.size(), i); } ltt->deleteAllTempTuples(); ASSERT_EQ(0, lttBlockCache->totalBlockCount()); ASSERT_EQ(0, lttBlockCache->allocatedMemory()); }
TEST_F(LargeTempTableTest, MultiBlock) { UniqueEngine engine = UniqueEngineBuilder().build(); LargeTempTableBlockCache* lttBlockCache = ExecutorContext::getExecutorContext()->lttBlockCache(); ASSERT_EQ(0, lttBlockCache->totalBlockCount()); const int INLINE_LEN = 15; const int NONINLINE_LEN = 50000; std::vector<std::string> names{ "pk", "val0", "val1", "val2", "dec0", "dec1", "dec2", "text0", "text1", "text2", "bigtext" }; TupleSchema* schema = Tools::buildSchema( // status byte: 1 VALUE_TYPE_BIGINT, // 8 VALUE_TYPE_DOUBLE, // 8 VALUE_TYPE_DOUBLE, // 8 VALUE_TYPE_DOUBLE, // 8 VALUE_TYPE_DECIMAL, // 16 VALUE_TYPE_DECIMAL, // 16 VALUE_TYPE_DECIMAL, // 16 std::make_pair(VALUE_TYPE_VARCHAR, INLINE_LEN), // 61 std::make_pair(VALUE_TYPE_VARCHAR, INLINE_LEN), // 61 std::make_pair(VALUE_TYPE_VARCHAR, INLINE_LEN), // 61 std::make_pair(VALUE_TYPE_VARCHAR, NONINLINE_LEN)); // 8 (pointer to non-inlined) // --> Tuple length is 272 bytes (not counting non-inlined data) auto ltt = makeUniqueTable(TableFactory::buildLargeTempTable( "ltmp", schema, names)); TableTuple tuple = ltt->tempTuple(); ASSERT_EQ(0, lttBlockCache->numPinnedEntries()); const int NUM_TUPLES = 500; // Attempt to insert enough rows so that we have more than one // block in this table. // inline data: // 136000 (500 * 272) // // Four kinds of non-inlined strings: // NULL 0 (125 * 0) // empty string 1500 (125 * 12, StringRef and length prefix) // half string 3126500 (125 * (25000 + 12)) // whole string 6251500 (125 * (50000 + 12)) // // Total --> 9515500 // // LTT blocks are 8MB so this data should use two blocks. for (int64_t i = 0; i < NUM_TUPLES; ++i) { Tools::setTupleValues(&tuple, i, 0.5 * i, 0.5 * i + 1, 0.5 * i + 2, Tools::toDec(0.5 * i), Tools::toDec(0.5 * i + 1), Tools::toDec(0.5 * i + 2), getStringValue(INLINE_LEN, i), getStringValue(INLINE_LEN, i + 1), getStringValue(INLINE_LEN, i + 2), getStringValue(NONINLINE_LEN, i)); ASSERT_TRUE(tuple.inlinedDataIsVolatile()); ASSERT_FALSE(tuple.nonInlinedDataIsVolatile()); ltt->insertTuple(tuple); } // The block we were inserting into will be pinned ASSERT_EQ(1, lttBlockCache->numPinnedEntries()); // Indicate that we are done inserting... ltt->finishInserts(); // Block is now unpinned ASSERT_EQ(0, lttBlockCache->numPinnedEntries()); ASSERT_EQ(2, ltt->allocatedBlockCount()); { TableIterator iter = ltt->iterator(); TableTuple iterTuple(ltt->schema()); int64_t i = 0; while (iter.next(iterTuple)) { boost::optional<std::string> inlineStr0 = getStringValue(INLINE_LEN, i); boost::optional<std::string> inlineStr1 = getStringValue(INLINE_LEN, i + 1); boost::optional<std::string> inlineStr2 = getStringValue(INLINE_LEN, i + 2); boost::optional<std::string> nonInlineStr = getStringValue(NONINLINE_LEN, i); assertTupleValuesEqual(&iterTuple, i, 0.5 * i, 0.5 * i + 1, 0.5 * i + 2, Tools::toDec(0.5 * i), Tools::toDec(0.5 * i + 1), Tools::toDec(0.5 * i + 2), inlineStr0, inlineStr1, inlineStr2, nonInlineStr); // Check volatility of inserted values NValue nv = iterTuple.getNValue(0); ASSERT_FALSE(nv.getVolatile()); // bigint nv = iterTuple.getNValue(7); // inlined varchar ASSERT_TRUE(nv.getVolatile()); // It can be made non-volatile by allocating in a pool: nv.allocateObjectFromPool(); ASSERT_FALSE(nv.getVolatile()); ASSERT_EQ(0, Tools::nvalueCompare(inlineStr0, nv)); nv = iterTuple.getNValue(10); // non-inlined varchar ASSERT_TRUE(nv.getVolatile()); // It can be made non-volatile by allocating in a pool: nv.allocateObjectFromPool(); ASSERT_FALSE(nv.getVolatile()); ASSERT_EQ(0, Tools::nvalueCompare(nonInlineStr, nv)); ++i; } ASSERT_EQ(500, i); } ltt->deleteAllTempTuples(); ASSERT_EQ(0, lttBlockCache->totalBlockCount()); ASSERT_EQ(0, lttBlockCache->allocatedMemory()); }