From dab708436ff33a7c04995fce59c7e348fe5dd605 Mon Sep 17 00:00:00 2001 From: xiyang Date: Fri, 23 Dec 2022 18:32:19 +0800 Subject: [PATCH] avoid setting result expression state at runtime --- src/function/vector_hash_operations.cpp | 3 +++ src/function/vector_list_operation.cpp | 7 ------- src/include/function/binary_operation_executor.h | 4 ---- src/include/function/boolean/boolean_operation_executor.h | 5 ----- src/include/function/hash/vector_hash_operations.h | 1 - src/include/function/null/null_operation_executor.h | 1 - src/include/function/ternary_operation_executor.h | 8 -------- src/include/function/unary_operation_executor.h | 1 - 8 files changed, 3 insertions(+), 27 deletions(-) diff --git a/src/function/vector_hash_operations.cpp b/src/function/vector_hash_operations.cpp index 961e3c537a..a591a7d6a4 100644 --- a/src/function/vector_hash_operations.cpp +++ b/src/function/vector_hash_operations.cpp @@ -7,6 +7,7 @@ namespace kuzu { namespace function { void VectorHashOperations::computeHash(ValueVector* operand, ValueVector* result) { + result->state = operand->state; assert(result->dataType.typeID == INT64); switch (operand->dataType.typeID) { case NODE_ID: { @@ -44,6 +45,8 @@ void VectorHashOperations::combineHash(ValueVector* left, ValueVector* right, Va assert(left->dataType.typeID == INT64); assert(left->dataType.typeID == right->dataType.typeID); assert(left->dataType.typeID == result->dataType.typeID); + // TODO(Xiyang/Guodong): we should resolve result state of hash vector at compile time. + result->state = !right->state->isFlat() ? right->state : left->state; BinaryOperationExecutor::execute( *left, *right, *result); } diff --git a/src/function/vector_list_operation.cpp b/src/function/vector_list_operation.cpp index 7c2bf880ad..247902f246 100644 --- a/src/function/vector_list_operation.cpp +++ b/src/function/vector_list_operation.cpp @@ -21,13 +21,6 @@ static string getListFunctionIncompatibleChildrenTypeErrorMsg( void VectorListOperations::ListCreation( const vector>& parameters, ValueVector& result) { assert(!parameters.empty() && result.dataType.typeID == LIST); - result.state = parameters[0]->state; - for (auto& parameter : parameters) { - if (!parameter->state->isFlat()) { - result.state = parameter->state; - break; - } - } result.resetOverflowBuffer(); auto& childType = parameters[0]->dataType; auto numBytesOfListElement = Types::getDataTypeSize(childType); diff --git a/src/include/function/binary_operation_executor.h b/src/include/function/binary_operation_executor.h index 4a915a25fb..d359e8936c 100644 --- a/src/include/function/binary_operation_executor.h +++ b/src/include/function/binary_operation_executor.h @@ -52,7 +52,6 @@ struct BinaryOperationExecutor { template static void executeBothFlat(ValueVector& left, ValueVector& right, ValueVector& result) { - result.state = left.state; auto lPos = left.state->selVector->selectedPositions[0]; auto rPos = right.state->selVector->selectedPositions[0]; auto resPos = result.state->selVector->selectedPositions[0]; @@ -66,7 +65,6 @@ struct BinaryOperationExecutor { template static void executeFlatUnFlat(ValueVector& left, ValueVector& right, ValueVector& result) { - result.state = right.state; auto lPos = left.state->selVector->selectedPositions[0]; if (left.isNull(lPos)) { result.setAllNull(); @@ -108,7 +106,6 @@ struct BinaryOperationExecutor { template static void executeUnFlatFlat(ValueVector& left, ValueVector& right, ValueVector& result) { - result.state = left.state; auto rPos = right.state->selVector->selectedPositions[0]; if (right.isNull(rPos)) { result.setAllNull(); @@ -151,7 +148,6 @@ struct BinaryOperationExecutor { typename OP_WRAPPER> static void executeBothUnFlat(ValueVector& left, ValueVector& right, ValueVector& result) { assert(left.state == right.state); - result.state = left.state; if (left.hasNoNullsGuarantee() && right.hasNoNullsGuarantee()) { if (result.state->selVector->isUnfiltered()) { for (uint64_t i = 0; i < result.state->selVector->selectedSize; i++) { diff --git a/src/include/function/boolean/boolean_operation_executor.h b/src/include/function/boolean/boolean_operation_executor.h index dde9e1219e..140c2c1ab3 100644 --- a/src/include/function/boolean/boolean_operation_executor.h +++ b/src/include/function/boolean/boolean_operation_executor.h @@ -33,7 +33,6 @@ struct BinaryBooleanOperationExecutor { template static inline void executeBothFlat(ValueVector& left, ValueVector& right, ValueVector& result) { - result.state = left.state; auto lPos = left.state->selVector->selectedPositions[0]; auto rPos = right.state->selVector->selectedPositions[0]; auto resPos = result.state->selVector->selectedPositions[0]; @@ -42,7 +41,6 @@ struct BinaryBooleanOperationExecutor { template static void executeFlatUnFlat(ValueVector& left, ValueVector& right, ValueVector& result) { - result.state = right.state; auto lPos = left.state->selVector->selectedPositions[0]; if (right.state->selVector->isUnfiltered()) { if (right.hasNoNullsGuarantee() && !left.isNull(lPos)) { @@ -71,7 +69,6 @@ struct BinaryBooleanOperationExecutor { template static void executeUnFlatFlat(ValueVector& left, ValueVector& right, ValueVector& result) { - result.state = left.state; auto rPos = right.state->selVector->selectedPositions[0]; if (left.state->selVector->isUnfiltered()) { if (left.hasNoNullsGuarantee() && !right.isNull(rPos)) { @@ -101,7 +98,6 @@ struct BinaryBooleanOperationExecutor { template static void executeBothUnFlat(ValueVector& left, ValueVector& right, ValueVector& result) { assert(left.state == right.state); - result.state = left.state; if (left.state->selVector->isUnfiltered()) { if (left.hasNoNullsGuarantee() && right.hasNoNullsGuarantee()) { for (auto i = 0u; i < left.state->selVector->selectedSize; ++i) { @@ -256,7 +252,6 @@ struct UnaryBooleanOperationExecutor { template static void executeSwitch(ValueVector& operand, ValueVector& result) { result.resetOverflowBuffer(); - result.state = operand.state; if (operand.state->isFlat()) { auto pos = operand.state->selVector->selectedPositions[0]; executeOnValue(operand, pos, result); diff --git a/src/include/function/hash/vector_hash_operations.h b/src/include/function/hash/vector_hash_operations.h index 58dbbd5a82..821ca95a34 100644 --- a/src/include/function/hash/vector_hash_operations.h +++ b/src/include/function/hash/vector_hash_operations.h @@ -9,7 +9,6 @@ namespace function { struct UnaryHashOperationExecutor { template static void execute(ValueVector& operand, ValueVector& result) { - result.state = operand.state; auto resultValues = (RESULT_TYPE*)result.getData(); if (operand.state->isFlat()) { auto pos = operand.state->selVector->selectedPositions[0]; diff --git a/src/include/function/null/null_operation_executor.h b/src/include/function/null/null_operation_executor.h index 1528469afe..43634d8eac 100644 --- a/src/include/function/null/null_operation_executor.h +++ b/src/include/function/null/null_operation_executor.h @@ -10,7 +10,6 @@ struct NullOperationExecutor { template static void execute(ValueVector& operand, ValueVector& result) { assert(result.dataType.typeID == BOOL); - result.state = operand.state; auto resultValues = (uint8_t*)result.getData(); if (operand.state->isFlat()) { auto pos = operand.state->selVector->selectedPositions[0]; diff --git a/src/include/function/ternary_operation_executor.h b/src/include/function/ternary_operation_executor.h index e77b8b5a48..b790ac2115 100644 --- a/src/include/function/ternary_operation_executor.h +++ b/src/include/function/ternary_operation_executor.h @@ -39,7 +39,6 @@ struct TernaryOperationExecutor { typename OP_WRAPPER> static void executeAllFlat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { - result.state = a.state; auto aPos = a.state->selVector->selectedPositions[0]; auto bPos = b.state->selVector->selectedPositions[0]; auto cPos = c.state->selVector->selectedPositions[0]; @@ -55,7 +54,6 @@ struct TernaryOperationExecutor { typename OP_WRAPPER> static void executeFlatFlatUnflat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { - result.state = c.state; auto aPos = a.state->selVector->selectedPositions[0]; auto bPos = b.state->selVector->selectedPositions[0]; if (a.isNull(aPos) || b.isNull(bPos)) { @@ -100,7 +98,6 @@ struct TernaryOperationExecutor { static void executeFlatUnflatUnflat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { assert(b.state == c.state); - result.state = b.state; auto aPos = a.state->selVector->selectedPositions[0]; if (a.isNull(aPos)) { result.setAllNull(); @@ -143,7 +140,6 @@ struct TernaryOperationExecutor { typename OP_WRAPPER> static void executeFlatUnflatFlat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { - result.state = b.state; auto aPos = a.state->selVector->selectedPositions[0]; auto cPos = c.state->selVector->selectedPositions[0]; if (a.isNull(aPos) || c.isNull(cPos)) { @@ -188,7 +184,6 @@ struct TernaryOperationExecutor { static void executeAllUnFlat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { assert(a.state == b.state && b.state == c.state); - result.state = a.state; if (a.hasNoNullsGuarantee() && b.hasNoNullsGuarantee() && c.hasNoNullsGuarantee()) { if (a.state->selVector->isUnfiltered()) { for (uint64_t i = 0; i < a.state->selVector->selectedSize; i++) { @@ -228,7 +223,6 @@ struct TernaryOperationExecutor { typename OP_WRAPPER> static void executeUnflatFlatFlat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { - result.state = a.state; auto bPos = b.state->selVector->selectedPositions[0]; auto cPos = c.state->selVector->selectedPositions[0]; if (b.isNull(bPos) || c.isNull(cPos)) { @@ -273,7 +267,6 @@ struct TernaryOperationExecutor { static void executeUnflatFlatUnflat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { assert(a.state == c.state); - result.state = a.state; auto bPos = b.state->selVector->selectedPositions[0]; if (b.isNull(bPos)) { result.setAllNull(); @@ -317,7 +310,6 @@ struct TernaryOperationExecutor { static void executeUnflatUnFlatFlat( ValueVector& a, ValueVector& b, ValueVector& c, ValueVector& result) { assert(a.state == b.state); - result.state = a.state; auto cPos = c.state->selVector->selectedPositions[0]; if (c.isNull(cPos)) { result.setAllNull(); diff --git a/src/include/function/unary_operation_executor.h b/src/include/function/unary_operation_executor.h index 439c13a0ac..526b3c93cf 100644 --- a/src/include/function/unary_operation_executor.h +++ b/src/include/function/unary_operation_executor.h @@ -48,7 +48,6 @@ struct UnaryOperationExecutor { template static void executeSwitch(ValueVector& operand, ValueVector& result) { result.resetOverflowBuffer(); - result.state = operand.state; auto resultValues = (RESULT_TYPE*)result.getData(); if (operand.state->isFlat()) { auto pos = operand.state->selVector->selectedPositions[0];