TEST_F(TableTupleTest, VolatilePoolBackedTuple) { UniqueEngine engine = UniqueEngineBuilder().build(); Pool pool; // 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))}; PoolBackedTupleStorage poolBackedTuple; poolBackedTuple.init(schema.get(), &pool); poolBackedTuple.allocateActiveTuple(); TableTuple &tuple = poolBackedTuple; Tools::setTupleValues(&tuple, int64_t(0), "foo", "foo bar"); // Pool-backed tuples are used as "scratch areas" so their data is // frequently mutated. NValues that reference them could have // their data changed. // // Non-inlined data is not volatile though. 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()); // After the NValue is made to be non-inlined (copied to temp string pool) // it is no longer volatile nv.allocateObjectFromPool(); ASSERT_FALSE(nv.getVolatile()); nv = tuple.getNValue(2); ASSERT_FALSE(nv.getVolatile()); }
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()); }