diff --git a/src/common/base/Arena.cpp b/src/common/base/Arena.cpp new file mode 100644 index 00000000000..0b816386a2a --- /dev/null +++ b/src/common/base/Arena.cpp @@ -0,0 +1,46 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#include "common/base/Arena.h" + +#include + +namespace nebula { + +void* Arena::allocateAligned(const std::size_t alloc) { + DCHECK_NE(alloc, 0); // don't allow zero sized allocation + // replace the modulo operation by bit and + static_assert(kAlignment && !(kAlignment & (kAlignment - 1)), "Align must be power of 2."); + const std::size_t pad = + kAlignment - (reinterpret_cast(currentPtr_) & (kAlignment - 1)); + const std::size_t consumption = alloc + pad; + if (UNLIKELY(consumption > kMaxChunkSize)) { + DLOG(FATAL) << "Arena can't allocate so large memory."; + return nullptr; + } + if (LIKELY(consumption <= availableSize_)) { + void* ptr = currentPtr_ + pad; + currentPtr_ += consumption; +#ifndef NDEBUG + allocatedSize_ += consumption; +#endif + availableSize_ -= consumption; + return ptr; + } else { + newChunk(std::max(alloc, kMinChunkSize)); + // The new operator will allocate the aligned memory + DCHECK_EQ(reinterpret_cast(currentPtr_) & (kAlignment - 1), 0); + void* ptr = currentPtr_; + currentPtr_ += alloc; +#ifndef NDEBUG + allocatedSize_ += alloc; +#endif + availableSize_ -= alloc; + return ptr; + } +} + +} // namespace nebula diff --git a/src/common/base/Arena.h b/src/common/base/Arena.h new file mode 100644 index 00000000000..e0de5876985 --- /dev/null +++ b/src/common/base/Arena.h @@ -0,0 +1,92 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#pragma once + +#include + +#include +#include +#include +#include + +#include "common/base/Logging.h" +#include "common/cpp/helpers.h" + +namespace nebula { + +// MT-unsafe arena allocator +// It's optimized for many small objects construct/destruct +class Arena : public boost::noncopyable, cpp::NonMovable { + public: + ~Arena() { + while (LIKELY(currentChunk_ != nullptr)) { + auto *prev = currentChunk_->prev; + delete[] currentChunk_; + currentChunk_ = prev; + } +#ifndef NDEBUG + allocatedSize_ = 0; +#endif + availableSize_ = 0; + currentPtr_ = nullptr; + } + + // The CPU access memory with the alignment, + // So construct object from alignment address will reduce the CPU access count then + // speed up read/write + void *allocateAligned(const std::size_t alloc); + +#ifndef NDEBUG + std::size_t allocatedSize() const { + return allocatedSize_; + } +#endif + + std::size_t availableSize() const { + return availableSize_; + } + + private: + static constexpr std::size_t kMinChunkSize = 4096; + static constexpr std::size_t kMaxChunkSize = std::numeric_limits::max(); + static constexpr std::size_t kAlignment = std::alignment_of::value; + + struct Chunk { + explicit Chunk(Chunk *p) : prev{p} {} + + union { + Chunk *prev{nullptr}; + std::byte aligned[kAlignment]; + }; + }; + + // allocate new chunk + // The current pointer will keep alignment + void newChunk(std::size_t size) { + DCHECK_NE(size, 0); + std::byte *ptr = new std::byte[size + sizeof(Chunk)]; + currentChunk_ = new (ptr) Chunk(currentChunk_); + availableSize_ = size; + currentPtr_ = (ptr + sizeof(Chunk)); + } + + Chunk *currentChunk_{nullptr}; +// These are debug info +// Remove to speed up in Release build +#ifndef NDEBUG + // total size allocated + std::size_t allocatedSize_{0}; +#endif + // total size which available to allocate + std::size_t availableSize_{0}; + // The total chunks size + // = allocatedSize_ + availableSize_ + Memory Deprecated (Size can't fit allocation) + // Current pointer to available memory address + std::byte *currentPtr_{nullptr}; +}; + +} // namespace nebula diff --git a/src/common/base/CMakeLists.txt b/src/common/base/CMakeLists.txt index d32bebf795c..95539f0266e 100644 --- a/src/common/base/CMakeLists.txt +++ b/src/common/base/CMakeLists.txt @@ -13,6 +13,7 @@ nebula_add_library( Status.cpp SanitizerOptions.cpp SignalHandler.cpp + Arena.cpp ${gdb_debug_script} ) diff --git a/src/common/base/ObjectPool.h b/src/common/base/ObjectPool.h index 04235f4bc88..acfe3a51b2f 100644 --- a/src/common/base/ObjectPool.h +++ b/src/common/base/ObjectPool.h @@ -13,6 +13,7 @@ #include #include +#include "common/base/Arena.h" #include "common/base/Logging.h" #include "common/cpp/helpers.h" @@ -26,26 +27,19 @@ class ObjectPool final : private boost::noncopyable, private cpp::NonMovable { public: ObjectPool() {} - ~ObjectPool() = default; + ~ObjectPool() { + clear(); + } void clear() { SLGuard g(lock_); objects_.clear(); } - template - T *add(T *obj) { - if constexpr (std::is_base_of::value) { - VLOG(3) << "New expression added into pool: " << obj->toString(); - } - SLGuard g(lock_); - objects_.emplace_back(obj); - return obj; - } - template T *makeAndAdd(Args &&... args) { - return add(new T(std::forward(args)...)); + void *ptr = arena_.allocateAligned(sizeof(T)); + return add(new (ptr) T(std::forward(args)...)); } bool empty() const { @@ -58,7 +52,7 @@ class ObjectPool final : private boost::noncopyable, private cpp::NonMovable { public: template explicit OwnershipHolder(T *obj) - : obj_(obj), deleteFn_([](void *p) { delete reinterpret_cast(p); }) {} + : obj_(obj), deleteFn_([](void *p) { reinterpret_cast(p)->~T(); }) {} ~OwnershipHolder() { deleteFn_(obj_); @@ -69,7 +63,18 @@ class ObjectPool final : private boost::noncopyable, private cpp::NonMovable { std::function deleteFn_; }; + template + T *add(T *obj) { + if constexpr (std::is_base_of::value) { + VLOG(3) << "New expression added into pool: " << obj->toString(); + } + SLGuard g(lock_); + objects_.emplace_back(obj); + return obj; + } + std::list objects_; + Arena arena_; folly::SpinLock lock_; }; diff --git a/src/common/base/test/ArenaBenchmark.cpp b/src/common/base/test/ArenaBenchmark.cpp new file mode 100644 index 00000000000..debbb57d802 --- /dev/null +++ b/src/common/base/test/ArenaBenchmark.cpp @@ -0,0 +1,90 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#include +#include +#include + +#include +#include + +#include "common/base/Arena.h" +#include "common/expression/LabelExpression.h" + +namespace nebula { + +class TestExpr : public LabelExpression { + public: + explicit TestExpr(const std::string &name = "") + : LabelExpression(reinterpret_cast(1), name) {} +}; + +BENCHMARK(DefaultAllocator, iters) { + std::size_t round = iters * 1000; + for (std::size_t _ = 0; _ < round; ++_) { + auto *expr = new TestExpr("Label"); + delete expr; + } +} + +BENCHMARK_RELATIVE(ArenaAllocator, iters) { + std::size_t round = iters * 1000; + Arena a; + for (std::size_t _ = 0; _ < round; ++_) { + auto *ptr = a.allocateAligned(sizeof(TestExpr)); + auto *expr = new (ptr) TestExpr("Label"); + expr->~TestExpr(); + } +} + +BENCHMARK_RELATIVE(FollyArenaAllocator, iters) { + std::size_t round = iters * 1000; + folly::SysArena a; + for (std::size_t _ = 0; _ < round; ++_) { + auto *ptr = a.allocate(sizeof(TestExpr)); + auto *expr = new (ptr) TestExpr("Label"); + expr->~TestExpr(); + } +} + +BENCHMARK_DRAW_LINE(); + +} // namespace nebula + +int main(int argc, char **argv) { + folly::init(&argc, &argv, true); + + folly::runBenchmarks(); + return 0; +} + +// CPU info +// Brand Raw: Intel(R) Xeon(R) CPU E5-2690 v2 @ 3.00GHz +// Hz Advertised Friendly: 3.0000 GHz +// Hz Actual Friendly: 3.2942 GHz +// Hz Advertised: (3000000000, 0) +// Hz Actual: (3294220000, 0) +// Arch: X86_64 +// Bits: 64 +// Count: 40 +// Arch String Raw: x86_64 +// L1 Data Cache Size: 32768 +// L1 Instruction Cache Size: 32768 +// L2 Cache Size: 262144 +// L2 Cache Line Size: 256 +// L2 Cache Associativity: 6 +// L3 Cache Size: 26214400 +// +// Build in Release mode +// +// ============================================================================ +// /home/shylock.huang/nebula/src/common/base/test/ArenaBenchmark.cpprelative time/iter iters/s +// ============================================================================ +// DefaultAllocator 36.59us 27.33K +// ArenaAllocator 145.89% 25.08us 39.87K +// FollyArenaAllocator 138.96% 26.33us 37.98K +// ---------------------------------------------------------------------------- +// ============================================================================ diff --git a/src/common/base/test/ArenaTest.cpp b/src/common/base/test/ArenaTest.cpp new file mode 100644 index 00000000000..d2f9f40d44d --- /dev/null +++ b/src/common/base/test/ArenaTest.cpp @@ -0,0 +1,46 @@ +/* Copyright (c) 2021 vesoft inc. All rights reserved. + * + * This source code is licensed under Apache 2.0 License, + * attached with Common Clause Condition 1.0, found in the LICENSES directory. + */ + +#include + +#include + +#include "common/base/Arena.h" + +namespace nebula { + +TEST(ArenaTest, Basic) { + Arena a; + + for (int i = 1; i < 4096; i += 8) { + void *ptr = a.allocateAligned(i); + EXPECT_EQ(reinterpret_cast(ptr) % std::alignment_of::value, 0); + } +} + +TEST(ArenaTest, Construct) { + Arena a; + { + void *ptr = a.allocateAligned(sizeof(std::string)); + auto *obj = new (ptr) std::string("Hello World!"); + EXPECT_EQ(*obj, "Hello World!"); + obj->~basic_string(); + } + { + void *ptr = a.allocateAligned(sizeof(int)); + auto *obj = new (ptr) int(3); // NOLINT + EXPECT_EQ(*obj, 3); + } + { + for (std::size_t i = 0; i < 1024; ++i) { + void *ptr = a.allocateAligned(sizeof(int)); + auto *obj = new (ptr) int(i); // NOLINT + EXPECT_EQ(*obj, i); + } + } +} + +} // namespace nebula diff --git a/src/common/base/test/CMakeLists.txt b/src/common/base/test/CMakeLists.txt index bfe1e4d5dd0..4963639cdf3 100644 --- a/src/common/base/test/CMakeLists.txt +++ b/src/common/base/test/CMakeLists.txt @@ -97,5 +97,35 @@ target_compile_options(range_vs_transform_bm PRIVATE -O3) nebula_add_test( NAME object_pool_test SOURCES ObjectPoolTest.cpp + OBJECTS $ LIBRARIES gtest gtest_main ) + +nebula_add_executable( + NAME arena_bm + SOURCES ArenaBenchmark.cpp + OBJECTS + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + LIBRARIES + follybenchmark + ${THRIFT_LIBRARIES} +) + +nebula_add_test( + NAME arena_test + SOURCES ArenaTest.cpp + OBJECTS + $ + LIBRARIES + gtest + gtest_main +) diff --git a/src/common/base/test/ObjectPoolTest.cpp b/src/common/base/test/ObjectPoolTest.cpp index a98a6064cc6..1bc9fd6c7a6 100644 --- a/src/common/base/test/ObjectPoolTest.cpp +++ b/src/common/base/test/ObjectPoolTest.cpp @@ -25,8 +25,8 @@ TEST(ObjectPoolTest, TestPooling) { ASSERT_EQ(instances, 0); ObjectPool pool; - ASSERT_NE(pool.add(new MyClass), nullptr); - ASSERT_NE(pool.add(new MyClass), nullptr); + ASSERT_NE(pool.makeAndAdd(), nullptr); + ASSERT_NE(pool.makeAndAdd(), nullptr); ASSERT_EQ(instances, 2); pool.clear(); diff --git a/src/common/expression/AggregateExpression.h b/src/common/expression/AggregateExpression.h index b38a6278f72..fd7fb68a5c4 100644 --- a/src/common/expression/AggregateExpression.h +++ b/src/common/expression/AggregateExpression.h @@ -24,7 +24,7 @@ class AggregateExpression final : public Expression { const std::string& name = "", Expression* arg = nullptr, bool distinct = false) { - return pool->add(new AggregateExpression(pool, name, arg, distinct)); + return pool->makeAndAdd(pool, name, arg, distinct); } const Value& eval(ExpressionContext& ctx) override; @@ -79,6 +79,7 @@ class AggregateExpression final : public Expression { } private: + friend ObjectPool; AggregateExpression(ObjectPool* pool, const std::string& name = "", Expression* arg = nullptr, diff --git a/src/common/expression/ArithmeticExpression.h b/src/common/expression/ArithmeticExpression.h index a1b536d8bfa..fd535167bbb 100644 --- a/src/common/expression/ArithmeticExpression.h +++ b/src/common/expression/ArithmeticExpression.h @@ -18,34 +18,34 @@ class ArithmeticExpression final : public BinaryExpression { static ArithmeticExpression* makeAdd(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new ArithmeticExpression(pool, Expression::Kind::kAdd, lhs, rhs)); + return pool->makeAndAdd(pool, Expression::Kind::kAdd, lhs, rhs); } static ArithmeticExpression* makeMinus(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new ArithmeticExpression(pool, Expression::Kind::kMinus, lhs, rhs)); + return pool->makeAndAdd(pool, Expression::Kind::kMinus, lhs, rhs); } static ArithmeticExpression* makeMultiply(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new ArithmeticExpression(pool, Expression::Kind::kMultiply, lhs, rhs)); + return pool->makeAndAdd(pool, Expression::Kind::kMultiply, lhs, rhs); } static ArithmeticExpression* makeDivision(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new ArithmeticExpression(pool, Expression::Kind::kDivision, lhs, rhs)); + return pool->makeAndAdd(pool, Expression::Kind::kDivision, lhs, rhs); } static ArithmeticExpression* makeMod(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new ArithmeticExpression(pool, Expression::Kind::kMod, lhs, rhs)); + return pool->makeAndAdd(pool, Expression::Kind::kMod, lhs, rhs); } // Construct arithmetic expression with given kind static ArithmeticExpression* makeKind(ObjectPool* pool, Kind kind, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new ArithmeticExpression(pool, kind, lhs, rhs)); + return pool->makeAndAdd(pool, kind, lhs, rhs); } const Value& eval(ExpressionContext& ctx) override; @@ -55,7 +55,8 @@ class ArithmeticExpression final : public BinaryExpression { std::string toString() const override; Expression* clone() const override { - return pool_->add(new ArithmeticExpression(pool_, kind(), left()->clone(), right()->clone())); + return pool_->makeAndAdd( + pool_, kind(), left()->clone(), right()->clone()); } bool isArithmeticExpr() const override { @@ -63,6 +64,7 @@ class ArithmeticExpression final : public BinaryExpression { } private: + friend ObjectPool; ArithmeticExpression(ObjectPool* pool, Kind kind, Expression* lhs, Expression* rhs) : BinaryExpression(pool, kind, lhs, rhs) {} diff --git a/src/common/expression/AttributeExpression.h b/src/common/expression/AttributeExpression.h index 36f028e3da1..616ceb64466 100644 --- a/src/common/expression/AttributeExpression.h +++ b/src/common/expression/AttributeExpression.h @@ -19,7 +19,7 @@ class AttributeExpression final : public BinaryExpression { static AttributeExpression *make(ObjectPool *pool, Expression *lhs = nullptr, Expression *rhs = nullptr) { - return pool->add(new AttributeExpression(pool, lhs, rhs)); + return pool->makeAndAdd(pool, lhs, rhs); } const Value &eval(ExpressionContext &ctx) override; @@ -33,6 +33,7 @@ class AttributeExpression final : public BinaryExpression { } private: + friend ObjectPool; explicit AttributeExpression(ObjectPool *pool, Expression *lhs = nullptr, Expression *rhs = nullptr) diff --git a/src/common/expression/CaseExpression.h b/src/common/expression/CaseExpression.h index 94c9d455eba..49ba7af08ae 100644 --- a/src/common/expression/CaseExpression.h +++ b/src/common/expression/CaseExpression.h @@ -13,7 +13,7 @@ namespace nebula { class CaseList final { public: static CaseList* make(ObjectPool* pool, size_t sz = 0) { - return pool->add(new CaseList(sz)); + return pool->makeAndAdd(sz); } void add(Expression* when, Expression* then) { @@ -31,6 +31,7 @@ class CaseList final { }; private: + friend ObjectPool; CaseList() = default; explicit CaseList(size_t sz) { items_.reserve(sz); @@ -48,8 +49,8 @@ class CaseExpression final : public Expression { CaseExpression& operator=(CaseExpression&&) = delete; static CaseExpression* make(ObjectPool* pool, CaseList* cases = nullptr, bool isGeneric = true) { - return !cases ? pool->add(new CaseExpression(pool)) - : pool->add(new CaseExpression(pool, cases, isGeneric)); + return !cases ? pool->makeAndAdd(pool) + : pool->makeAndAdd(pool, cases, isGeneric); } bool operator==(const Expression& rhs) const override; @@ -128,6 +129,7 @@ class CaseExpression final : public Expression { } private: + friend ObjectPool; explicit CaseExpression(ObjectPool* pool) : Expression(pool, Kind::kCase), isGeneric_(true) {} CaseExpression(ObjectPool* pool, CaseList* cases, bool isGeneric) diff --git a/src/common/expression/ColumnExpression.h b/src/common/expression/ColumnExpression.h index 43e2d9b47d9..1ca147c294e 100644 --- a/src/common/expression/ColumnExpression.h +++ b/src/common/expression/ColumnExpression.h @@ -20,7 +20,7 @@ class ColumnExpression final : public Expression { ColumnExpression& operator=(ColumnExpression&&) = delete; static ColumnExpression* make(ObjectPool* pool, int32_t index = 0) { - return pool->add(new ColumnExpression(pool, index)); + return pool->makeAndAdd(pool, index); } const Value& eval(ExpressionContext& ctx) override; @@ -36,6 +36,7 @@ class ColumnExpression final : public Expression { bool operator==(const Expression& expr) const override; private: + friend ObjectPool; explicit ColumnExpression(ObjectPool* pool, int32_t index = 0) : Expression(pool, Kind::kColumn), index_(index) {} diff --git a/src/common/expression/ConstantExpression.h b/src/common/expression/ConstantExpression.h index c189564cb75..8c86bacdcd7 100644 --- a/src/common/expression/ConstantExpression.h +++ b/src/common/expression/ConstantExpression.h @@ -19,7 +19,7 @@ class ConstantExpression : public Expression { ConstantExpression& operator=(ConstantExpression&&) = delete; static ConstantExpression* make(ObjectPool* pool, Value v = Value(NullType::__NULL__)) { - return pool->add(new ConstantExpression(pool, v)); + return pool->makeAndAdd(pool, v); } bool operator==(const Expression& rhs) const override; @@ -46,6 +46,7 @@ class ConstantExpression : public Expression { } private: + friend ObjectPool; explicit ConstantExpression(ObjectPool* pool, Value v = Value(NullType::__NULL__)) : Expression(pool, Kind::kConstant), val_(std::move(v)) {} diff --git a/src/common/expression/ContainerExpression.h b/src/common/expression/ContainerExpression.h index 1bf2f7240c5..56cb375f113 100644 --- a/src/common/expression/ContainerExpression.h +++ b/src/common/expression/ContainerExpression.h @@ -13,7 +13,7 @@ namespace nebula { class ExpressionList final { public: static ExpressionList *make(ObjectPool *pool, size_t sz = 0) { - return pool->add(new ExpressionList(sz)); + return pool->makeAndAdd(sz); } ExpressionList &add(Expression *expr) { @@ -26,6 +26,7 @@ class ExpressionList final { } private: + friend ObjectPool; ExpressionList() = default; explicit ExpressionList(size_t sz) { items_.reserve(sz); @@ -38,7 +39,7 @@ class ExpressionList final { class MapItemList final { public: static MapItemList *make(ObjectPool *pool, size_t sz = 0) { - return pool->add(new MapItemList(sz)); + return pool->makeAndAdd(sz); } MapItemList &add(const std::string &key, Expression *value) { @@ -51,6 +52,7 @@ class MapItemList final { } private: + friend ObjectPool; MapItemList() = default; explicit MapItemList(size_t sz) { items_.reserve(sz); @@ -67,8 +69,8 @@ class ListExpression final : public Expression { ListExpression &operator=(ListExpression &&) = delete; static ListExpression *make(ObjectPool *pool, ExpressionList *items = nullptr) { - return items == nullptr ? pool->add(new ListExpression(pool)) - : pool->add(new ListExpression(pool, items)); + return items == nullptr ? pool->makeAndAdd(pool) + : pool->makeAndAdd(pool, items); } const Value &eval(ExpressionContext &ctx) override; @@ -113,6 +115,7 @@ class ListExpression final : public Expression { } private: + friend ObjectPool; explicit ListExpression(ObjectPool *pool) : Expression(pool, Kind::kList) {} ListExpression(ObjectPool *pool, ExpressionList *items) : Expression(pool, Kind::kList) { @@ -134,8 +137,8 @@ class SetExpression final : public Expression { SetExpression &operator=(SetExpression &&) = delete; static SetExpression *make(ObjectPool *pool, ExpressionList *items = nullptr) { - return items == nullptr ? pool->add(new SetExpression(pool)) - : pool->add(new SetExpression(pool, items)); + return items == nullptr ? pool->makeAndAdd(pool) + : pool->makeAndAdd(pool, items); } const Value &eval(ExpressionContext &ctx) override; @@ -180,6 +183,7 @@ class SetExpression final : public Expression { } private: + friend ObjectPool; explicit SetExpression(ObjectPool *pool) : Expression(pool, Kind::kSet) {} SetExpression(ObjectPool *pool, ExpressionList *items) : Expression(pool, Kind::kSet) { @@ -201,8 +205,8 @@ class MapExpression final : public Expression { MapExpression &operator=(MapExpression &&) = delete; static MapExpression *make(ObjectPool *pool, MapItemList *items = nullptr) { - return items == nullptr ? pool->add(new MapExpression(pool)) - : pool->add(new MapExpression(pool, items)); + return items == nullptr ? pool->makeAndAdd(pool) + : pool->makeAndAdd(pool, items); } using Item = std::pair; @@ -249,6 +253,7 @@ class MapExpression final : public Expression { } private: + friend ObjectPool; explicit MapExpression(ObjectPool *pool) : Expression(pool, Kind::kMap) {} MapExpression(ObjectPool *pool, MapItemList *items) : Expression(pool, Kind::kMap) { diff --git a/src/common/expression/EdgeExpression.h b/src/common/expression/EdgeExpression.h index 1e7fffd5019..ed2ffcbb869 100644 --- a/src/common/expression/EdgeExpression.h +++ b/src/common/expression/EdgeExpression.h @@ -22,7 +22,7 @@ class EdgeExpression final : public Expression { EdgeExpression& operator=(EdgeExpression&&) = delete; static EdgeExpression* make(ObjectPool* pool) { - return pool->add(new EdgeExpression(pool)); + return pool->makeAndAdd(pool); } const Value& eval(ExpressionContext& ctx) override; @@ -42,6 +42,7 @@ class EdgeExpression final : public Expression { } private: + friend ObjectPool; explicit EdgeExpression(ObjectPool* pool) : Expression(pool, Kind::kEdge) {} void writeTo(Encoder& encoder) const override { diff --git a/src/common/expression/FunctionCallExpression.h b/src/common/expression/FunctionCallExpression.h index c752b54d910..77132aa5f06 100644 --- a/src/common/expression/FunctionCallExpression.h +++ b/src/common/expression/FunctionCallExpression.h @@ -16,7 +16,7 @@ namespace nebula { class ArgumentList final { public: static ArgumentList* make(ObjectPool* pool, size_t sz = 0) { - return pool->add(new ArgumentList(sz)); + return pool->makeAndAdd(sz); } void addArgument(Expression* arg) { @@ -48,6 +48,7 @@ class ArgumentList final { bool operator==(const ArgumentList& rhs) const; private: + friend ObjectPool; ArgumentList() = default; explicit ArgumentList(size_t sz) { args_.reserve(sz); @@ -68,8 +69,8 @@ class FunctionCallExpression final : public Expression { const std::string& name = "", ArgumentList* args = nullptr) { return args == nullptr - ? pool->add(new FunctionCallExpression(pool, name, ArgumentList::make(pool))) - : pool->add(new FunctionCallExpression(pool, name, args)); + ? pool->makeAndAdd(pool, name, ArgumentList::make(pool)) + : pool->makeAndAdd(pool, name, args); } static FunctionCallExpression* make(ObjectPool* pool, @@ -79,7 +80,7 @@ class FunctionCallExpression final : public Expression { for (auto* arg : args) { argList->addArgument(arg); } - return pool->add(new FunctionCallExpression(pool, name, argList)); + return FunctionCallExpression::make(pool, name, argList); } const Value& eval(ExpressionContext& ctx) override; @@ -115,6 +116,7 @@ class FunctionCallExpression final : public Expression { } private: + friend ObjectPool; FunctionCallExpression(ObjectPool* pool, const std::string& name, ArgumentList* args) : Expression(pool, Kind::kFunctionCall), name_(name), args_(args) { if (!name_.empty()) { diff --git a/src/common/expression/LabelAttributeExpression.h b/src/common/expression/LabelAttributeExpression.h index 315031fefab..3ed02581f01 100644 --- a/src/common/expression/LabelAttributeExpression.h +++ b/src/common/expression/LabelAttributeExpression.h @@ -22,7 +22,7 @@ class LabelAttributeExpression final : public Expression { static LabelAttributeExpression* make(ObjectPool* pool, LabelExpression* lhs = nullptr, ConstantExpression* rhs = nullptr) { - return pool->add(new LabelAttributeExpression(pool, lhs, rhs)); + return pool->makeAndAdd(pool, lhs, rhs); } bool operator==(const Expression& rhs) const override { @@ -65,6 +65,7 @@ class LabelAttributeExpression final : public Expression { std::string toString() const override; private: + friend ObjectPool; explicit LabelAttributeExpression(ObjectPool* pool, LabelExpression* lhs = nullptr, ConstantExpression* rhs = nullptr) diff --git a/src/common/expression/LabelExpression.h b/src/common/expression/LabelExpression.h index b91609165f0..fae8bf00a5b 100644 --- a/src/common/expression/LabelExpression.h +++ b/src/common/expression/LabelExpression.h @@ -18,7 +18,7 @@ class LabelExpression : public Expression { LabelExpression& operator=(LabelExpression&&) = delete; static LabelExpression* make(ObjectPool* pool, const std::string& name = "") { - return pool->add(new LabelExpression(pool, name)); + return pool->makeAndAdd(pool, name); } bool operator==(const Expression& rhs) const override; @@ -38,6 +38,7 @@ class LabelExpression : public Expression { } protected: + friend ObjectPool; explicit LabelExpression(ObjectPool* pool, const std::string& name = "") : Expression(pool, Kind::kLabel), name_(name) {} diff --git a/src/common/expression/ListComprehensionExpression.h b/src/common/expression/ListComprehensionExpression.h index 26723d1f0ff..dd6c738de92 100644 --- a/src/common/expression/ListComprehensionExpression.h +++ b/src/common/expression/ListComprehensionExpression.h @@ -22,7 +22,8 @@ class ListComprehensionExpression final : public Expression { Expression* collection = nullptr, Expression* filter = nullptr, Expression* mapping = nullptr) { - return pool->add(new ListComprehensionExpression(pool, innerVar, collection, filter, mapping)); + return pool->makeAndAdd( + pool, innerVar, collection, filter, mapping); } bool operator==(const Expression& rhs) const override; @@ -100,6 +101,7 @@ class ListComprehensionExpression final : public Expression { } private: + friend ObjectPool; explicit ListComprehensionExpression(ObjectPool* pool, const std::string& innerVar = "", Expression* collection = nullptr, diff --git a/src/common/expression/LogicalExpression.h b/src/common/expression/LogicalExpression.h index f64de79a402..91685c5bce1 100644 --- a/src/common/expression/LogicalExpression.h +++ b/src/common/expression/LogicalExpression.h @@ -17,30 +17,30 @@ class LogicalExpression final : public Expression { static LogicalExpression* makeAnd(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return (lhs && rhs) ? pool->add(new LogicalExpression(pool, Kind::kLogicalAnd, lhs, rhs)) - : pool->add(new LogicalExpression(pool, Kind::kLogicalAnd)); + return (lhs && rhs) ? pool->makeAndAdd(pool, Kind::kLogicalAnd, lhs, rhs) + : pool->makeAndAdd(pool, Kind::kLogicalAnd); } static LogicalExpression* makeOr(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return (lhs && rhs) ? pool->add(new LogicalExpression(pool, Kind::kLogicalOr, lhs, rhs)) - : pool->add(new LogicalExpression(pool, Kind::kLogicalOr)); + return (lhs && rhs) ? pool->makeAndAdd(pool, Kind::kLogicalOr, lhs, rhs) + : pool->makeAndAdd(pool, Kind::kLogicalOr); } static LogicalExpression* makeXor(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return (lhs && rhs) ? pool->add(new LogicalExpression(pool, Kind::kLogicalXor, lhs, rhs)) - : pool->add(new LogicalExpression(pool, Kind::kLogicalXor)); + return (lhs && rhs) ? pool->makeAndAdd(pool, Kind::kLogicalXor, lhs, rhs) + : pool->makeAndAdd(pool, Kind::kLogicalXor); } static LogicalExpression* makeKind(ObjectPool* pool, Kind kind, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return (lhs && rhs) ? pool->add(new LogicalExpression(pool, kind, lhs, rhs)) - : pool->add(new LogicalExpression(pool, kind)); + return (lhs && rhs) ? pool->makeAndAdd(pool, kind, lhs, rhs) + : pool->makeAndAdd(pool, kind); } const Value& eval(ExpressionContext& ctx) override; @@ -50,12 +50,12 @@ class LogicalExpression final : public Expression { void accept(ExprVisitor* visitor) override; Expression* clone() const override { - auto copy = new LogicalExpression(pool_, kind()); + auto copy = LogicalExpression::makeKind(pool_, kind()); copy->operands_.resize(operands_.size()); for (auto i = 0u; i < operands_.size(); i++) { copy->operands_[i] = operands_[i]->clone(); } - return pool_->add(copy); + return copy; } bool operator==(const Expression& rhs) const override; @@ -104,6 +104,7 @@ class LogicalExpression final : public Expression { } private: + friend ObjectPool; LogicalExpression(ObjectPool* pool, Kind kind) : Expression(pool, kind) {} LogicalExpression(ObjectPool* pool, Kind kind, Expression* lhs, Expression* rhs) diff --git a/src/common/expression/MatchPathPatternExpression.h b/src/common/expression/MatchPathPatternExpression.h index 8e09be30dda..a80afe6345e 100644 --- a/src/common/expression/MatchPathPatternExpression.h +++ b/src/common/expression/MatchPathPatternExpression.h @@ -20,7 +20,7 @@ class MatchPathPatternExpression final : public Expression { static MatchPathPatternExpression* make(ObjectPool* pool, std::unique_ptr&& matchPath) { - return pool->add(new MatchPathPatternExpression(pool, std::move(matchPath))); + return pool->makeAndAdd(pool, std::move(matchPath)); } const Value& eval(ExpressionContext& ctx) override; @@ -55,6 +55,7 @@ class MatchPathPatternExpression final : public Expression { } private: + friend ObjectPool; explicit MatchPathPatternExpression(ObjectPool* pool, std::unique_ptr&& matchPath) : Expression(pool, Kind::kMatchPathPattern), matchPath_(std::move(matchPath)) {} diff --git a/src/common/expression/PathBuildExpression.h b/src/common/expression/PathBuildExpression.h index 4736ad7e30c..ea75275cf3e 100644 --- a/src/common/expression/PathBuildExpression.h +++ b/src/common/expression/PathBuildExpression.h @@ -18,7 +18,7 @@ class PathBuildExpression final : public Expression { PathBuildExpression& operator=(PathBuildExpression&&) = delete; static PathBuildExpression* make(ObjectPool* pool) { - return pool->add(new PathBuildExpression(pool)); + return pool->makeAndAdd(pool); } const Value& eval(ExpressionContext& ctx) override; @@ -54,6 +54,7 @@ class PathBuildExpression final : public Expression { } private: + friend ObjectPool; explicit PathBuildExpression(ObjectPool* pool) : Expression(pool, Kind::kPathBuild) {} void writeTo(Encoder& encoder) const override; diff --git a/src/common/expression/PredicateExpression.h b/src/common/expression/PredicateExpression.h index 9792e8f425d..db59ef64d7c 100644 --- a/src/common/expression/PredicateExpression.h +++ b/src/common/expression/PredicateExpression.h @@ -30,7 +30,7 @@ class PredicateExpression final : public Expression { const std::string& innerVar = "", Expression* collection = nullptr, Expression* filter = nullptr) { - return pool->add(new PredicateExpression(pool, name, innerVar, collection, filter)); + return pool->makeAndAdd(pool, name, innerVar, collection, filter); } bool operator==(const Expression& rhs) const override; @@ -100,6 +100,7 @@ class PredicateExpression final : public Expression { } private: + friend ObjectPool; explicit PredicateExpression(ObjectPool* pool, const std::string& name = "", const std::string& innerVar = "", diff --git a/src/common/expression/PropertyExpression.h b/src/common/expression/PropertyExpression.h index 3b7bd5e26cf..4054baab5af 100644 --- a/src/common/expression/PropertyExpression.h +++ b/src/common/expression/PropertyExpression.h @@ -71,7 +71,7 @@ class EdgePropertyExpression final : public PropertyExpression { static EdgePropertyExpression* make(ObjectPool* pool, const std::string& edge = "", const std::string& prop = "") { - return pool->add(new EdgePropertyExpression(pool, edge, prop)); + return pool->makeAndAdd(pool, edge, prop); } const Value& eval(ExpressionContext& ctx) override; @@ -83,6 +83,7 @@ class EdgePropertyExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit EdgePropertyExpression(ObjectPool* pool, const std::string& edge = "", const std::string& prop = "") @@ -101,7 +102,7 @@ class TagPropertyExpression final : public PropertyExpression { static TagPropertyExpression* make(ObjectPool* pool, const std::string& tag = "", const std::string& prop = "") { - return pool->add(new TagPropertyExpression(pool, tag, prop)); + return pool->makeAndAdd(pool, tag, prop); } const Value& eval(ExpressionContext& ctx) override; @@ -113,6 +114,7 @@ class TagPropertyExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit TagPropertyExpression(ObjectPool* pool, const std::string& tag = "", const std::string& prop = "") @@ -132,7 +134,7 @@ class LabelTagPropertyExpression final : public PropertyExpression { Expression* label = nullptr, const std::string& tag = "", const std::string& prop = "") { - return pool->add(new LabelTagPropertyExpression(pool, label, tag, prop)); + return pool->makeAndAdd(pool, label, tag, prop); } std::string toString() const override; @@ -160,6 +162,7 @@ class LabelTagPropertyExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit LabelTagPropertyExpression(ObjectPool* pool, Expression* label = nullptr, const std::string& tag = "", @@ -180,7 +183,7 @@ class InputPropertyExpression final : public PropertyExpression { InputPropertyExpression& operator=(InputPropertyExpression&&) = delete; static InputPropertyExpression* make(ObjectPool* pool, const std::string& prop = "") { - return pool->add(new InputPropertyExpression(pool, prop)); + return pool->makeAndAdd(pool, prop); } const Value& eval(ExpressionContext& ctx) override; @@ -192,6 +195,7 @@ class InputPropertyExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit InputPropertyExpression(ObjectPool* pool, const std::string& prop = "") : PropertyExpression(pool, Kind::kInputProperty, kInputRef, "", prop) {} }; @@ -205,7 +209,7 @@ class VariablePropertyExpression final : public PropertyExpression { static VariablePropertyExpression* make(ObjectPool* pool, const std::string& var = "", const std::string& prop = "") { - return pool->add(new VariablePropertyExpression(pool, var, prop)); + return pool->makeAndAdd(pool, var, prop); } const Value& eval(ExpressionContext& ctx) override; @@ -219,6 +223,7 @@ class VariablePropertyExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit VariablePropertyExpression(ObjectPool* pool, const std::string& var = "", const std::string& prop = "") @@ -234,7 +239,7 @@ class SourcePropertyExpression final : public PropertyExpression { static SourcePropertyExpression* make(ObjectPool* pool, const std::string& tag = "", const std::string& prop = "") { - return pool->add(new SourcePropertyExpression(pool, tag, prop)); + return pool->makeAndAdd(pool, tag, prop); } const Value& eval(ExpressionContext& ctx) override; @@ -246,6 +251,7 @@ class SourcePropertyExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit SourcePropertyExpression(ObjectPool* pool, const std::string& tag = "", const std::string& prop = "") @@ -264,7 +270,7 @@ class DestPropertyExpression final : public PropertyExpression { static DestPropertyExpression* make(ObjectPool* pool, const std::string& tag = "", const std::string& prop = "") { - return pool->add(new DestPropertyExpression(pool, tag, prop)); + return pool->makeAndAdd(pool, tag, prop); } const Value& eval(ExpressionContext& ctx) override; @@ -276,6 +282,7 @@ class DestPropertyExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit DestPropertyExpression(ObjectPool* pool, const std::string& tag = "", const std::string& prop = "") @@ -289,7 +296,7 @@ class EdgeSrcIdExpression final : public PropertyExpression { EdgeSrcIdExpression& operator=(EdgeSrcIdExpression&&) = delete; static EdgeSrcIdExpression* make(ObjectPool* pool, const std::string& edge = "") { - return pool->add(new EdgeSrcIdExpression(pool, edge)); + return pool->makeAndAdd(pool, edge); } const Value& eval(ExpressionContext& ctx) override; @@ -301,6 +308,7 @@ class EdgeSrcIdExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit EdgeSrcIdExpression(ObjectPool* pool, const std::string& edge = "") : PropertyExpression(pool, Kind::kEdgeSrc, "", edge, kSrc) {} @@ -315,7 +323,7 @@ class EdgeTypeExpression final : public PropertyExpression { EdgeTypeExpression& operator=(EdgeTypeExpression&&) = delete; static EdgeTypeExpression* make(ObjectPool* pool, const std::string& edge = "") { - return pool->add(new EdgeTypeExpression(pool, edge)); + return pool->makeAndAdd(pool, edge); } const Value& eval(ExpressionContext& ctx) override; @@ -327,6 +335,7 @@ class EdgeTypeExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit EdgeTypeExpression(ObjectPool* pool, const std::string& edge = "") : PropertyExpression(pool, Kind::kEdgeType, "", edge, kType) {} @@ -341,7 +350,7 @@ class EdgeRankExpression final : public PropertyExpression { EdgeRankExpression& operator=(EdgeRankExpression&&) = delete; static EdgeRankExpression* make(ObjectPool* pool, const std::string& edge = "") { - return pool->add(new EdgeRankExpression(pool, edge)); + return pool->makeAndAdd(pool, edge); } const Value& eval(ExpressionContext& ctx) override; @@ -353,6 +362,7 @@ class EdgeRankExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit EdgeRankExpression(ObjectPool* pool, const std::string& edge = "") : PropertyExpression(pool, Kind::kEdgeRank, "", edge, kRank) {} @@ -367,7 +377,7 @@ class EdgeDstIdExpression final : public PropertyExpression { EdgeDstIdExpression& operator=(EdgeDstIdExpression&&) = delete; static EdgeDstIdExpression* make(ObjectPool* pool, const std::string& edge = "") { - return pool->add(new EdgeDstIdExpression(pool, edge)); + return pool->makeAndAdd(pool, edge); } const Value& eval(ExpressionContext& ctx) override; @@ -379,6 +389,7 @@ class EdgeDstIdExpression final : public PropertyExpression { } private: + friend ObjectPool; explicit EdgeDstIdExpression(ObjectPool* pool, const std::string& edge = "") : PropertyExpression(pool, Kind::kEdgeDst, "", edge, kDst) {} diff --git a/src/common/expression/ReduceExpression.h b/src/common/expression/ReduceExpression.h index 130be05672f..096e92d02ab 100644 --- a/src/common/expression/ReduceExpression.h +++ b/src/common/expression/ReduceExpression.h @@ -20,8 +20,8 @@ class ReduceExpression final : public Expression { const std::string& innerVar = "", Expression* collection = nullptr, Expression* mapping = nullptr) { - return pool->add( - new ReduceExpression(pool, accumulator, initial, innerVar, collection, mapping)); + return pool->makeAndAdd( + pool, accumulator, initial, innerVar, collection, mapping); } bool operator==(const Expression& rhs) const override; @@ -99,6 +99,7 @@ class ReduceExpression final : public Expression { } private: + friend ObjectPool; explicit ReduceExpression(ObjectPool* pool, const std::string& accumulator = "", Expression* initial = nullptr, diff --git a/src/common/expression/RelationalExpression.h b/src/common/expression/RelationalExpression.h index 7191fed9277..b7294fb9546 100644 --- a/src/common/expression/RelationalExpression.h +++ b/src/common/expression/RelationalExpression.h @@ -14,91 +14,91 @@ class RelationalExpression final : public BinaryExpression { static RelationalExpression* makeEQ(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelEQ, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelEQ, lhs, rhs); } static RelationalExpression* makeNE(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelNE, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelNE, lhs, rhs); } static RelationalExpression* makeLT(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelLT, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelLT, lhs, rhs); } static RelationalExpression* makeLE(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelLE, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelLE, lhs, rhs); } static RelationalExpression* makeGT(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelGT, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelGT, lhs, rhs); } static RelationalExpression* makeGE(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelGE, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelGE, lhs, rhs); } static RelationalExpression* makeREG(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelREG, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelREG, lhs, rhs); } static RelationalExpression* makeIn(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelIn, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelIn, lhs, rhs); } static RelationalExpression* makeNotIn(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kRelNotIn, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kRelNotIn, lhs, rhs); } static RelationalExpression* makeContains(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kContains, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kContains, lhs, rhs); } static RelationalExpression* makeNotContains(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kNotContains, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kNotContains, lhs, rhs); } static RelationalExpression* makeStartsWith(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kStartsWith, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kStartsWith, lhs, rhs); } static RelationalExpression* makeNotStartsWith(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kNotStartsWith, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kNotStartsWith, lhs, rhs); } static RelationalExpression* makeEndsWith(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kEndsWith, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kEndsWith, lhs, rhs); } static RelationalExpression* makeNotEndsWith(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, Kind::kNotEndsWith, lhs, rhs)); + return pool->makeAndAdd(pool, Kind::kNotEndsWith, lhs, rhs); } // Construct a kind-specified relational expression @@ -106,7 +106,7 @@ class RelationalExpression final : public BinaryExpression { Kind kind, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new RelationalExpression(pool, kind, lhs, rhs)); + return pool->makeAndAdd(pool, kind, lhs, rhs); } const Value& eval(ExpressionContext& ctx) override; @@ -116,7 +116,7 @@ class RelationalExpression final : public BinaryExpression { void accept(ExprVisitor* visitor) override; Expression* clone() const override { - return pool_->add(new RelationalExpression(pool_, kind(), left()->clone(), right()->clone())); + return RelationalExpression::makeKind(pool_, kind(), left()->clone(), right()->clone()); } bool isRelExpr() const override { @@ -124,6 +124,7 @@ class RelationalExpression final : public BinaryExpression { } private: + friend ObjectPool; RelationalExpression(ObjectPool* pool, Kind kind, Expression* lhs, Expression* rhs) : BinaryExpression(pool, kind, lhs, rhs) {} diff --git a/src/common/expression/SubscriptExpression.h b/src/common/expression/SubscriptExpression.h index d959a7f7cc5..62b301a4a2f 100644 --- a/src/common/expression/SubscriptExpression.h +++ b/src/common/expression/SubscriptExpression.h @@ -17,7 +17,7 @@ class SubscriptExpression final : public BinaryExpression { static SubscriptExpression* make(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) { - return pool->add(new SubscriptExpression(pool, lhs, rhs)); + return pool->makeAndAdd(pool, lhs, rhs); } const Value& eval(ExpressionContext& ctx) override; @@ -31,6 +31,7 @@ class SubscriptExpression final : public BinaryExpression { } private: + friend ObjectPool; explicit SubscriptExpression(ObjectPool* pool, Expression* lhs = nullptr, Expression* rhs = nullptr) @@ -46,8 +47,8 @@ class SubscriptRangeExpression final : public Expression { Expression* list = nullptr, Expression* lo = nullptr, Expression* hi = nullptr) { - return !list && !lo && !hi ? pool->add(new SubscriptRangeExpression(pool)) - : pool->add(new SubscriptRangeExpression(pool, list, lo, hi)); + return !list && !lo && !hi ? pool->makeAndAdd(pool) + : pool->makeAndAdd(pool, list, lo, hi); } const Value& eval(ExpressionContext& ctx) override; @@ -102,6 +103,7 @@ class SubscriptRangeExpression final : public Expression { } private: + friend ObjectPool; // for decode ctor explicit SubscriptRangeExpression(ObjectPool* pool) : Expression(pool, Kind::kSubscriptRange), list_(nullptr), lo_(nullptr), hi_(nullptr) {} diff --git a/src/common/expression/TextSearchExpression.h b/src/common/expression/TextSearchExpression.h index 373d7c8f77d..9c77f8667c9 100644 --- a/src/common/expression/TextSearchExpression.h +++ b/src/common/expression/TextSearchExpression.h @@ -17,7 +17,7 @@ class TextSearchArgument final { const std::string& from, const std::string& prop, const std::string& val) { - return pool->add(new TextSearchArgument(from, prop, val)); + return pool->makeAndAdd(from, prop, val); } ~TextSearchArgument() = default; @@ -75,6 +75,7 @@ class TextSearchArgument final { std::string toString() const; private: + friend ObjectPool; TextSearchArgument(const std::string& from, const std::string& prop, const std::string& val) : from_(from), prop_(prop), val_(val) {} @@ -91,19 +92,23 @@ class TextSearchArgument final { class TextSearchExpression : public Expression { public: static TextSearchExpression* makePrefix(ObjectPool* pool, TextSearchArgument* arg) { - return pool->add(new TextSearchExpression(pool, Kind::kTSPrefix, arg)); + return pool->makeAndAdd(pool, Kind::kTSPrefix, arg); } static TextSearchExpression* makeWildcard(ObjectPool* pool, TextSearchArgument* arg) { - return pool->add(new TextSearchExpression(pool, Kind::kTSWildcard, arg)); + return pool->makeAndAdd(pool, Kind::kTSWildcard, arg); } static TextSearchExpression* makeRegexp(ObjectPool* pool, TextSearchArgument* arg) { - return pool->add(new TextSearchExpression(pool, Kind::kTSRegexp, arg)); + return pool->makeAndAdd(pool, Kind::kTSRegexp, arg); } static TextSearchExpression* makeFuzzy(ObjectPool* pool, TextSearchArgument* arg) { - return pool->add(new TextSearchExpression(pool, Kind::kTSFuzzy, arg)); + return pool->makeAndAdd(pool, Kind::kTSFuzzy, arg); + } + + static TextSearchExpression* make(ObjectPool* pool, Kind kind, TextSearchArgument* arg) { + return pool->makeAndAdd(pool, kind, arg); } bool operator==(const Expression& rhs) const override; @@ -121,7 +126,7 @@ class TextSearchExpression : public Expression { Expression* clone() const override { auto arg = TextSearchArgument::make(pool_, arg_->from(), arg_->prop(), arg_->val()); - return pool_->add(new TextSearchExpression(pool_, kind_, arg)); + return TextSearchExpression::make(pool_, kind_, arg); } const TextSearchArgument* arg() const { @@ -137,6 +142,7 @@ class TextSearchExpression : public Expression { } private: + friend ObjectPool; TextSearchExpression(ObjectPool* pool, Kind kind, TextSearchArgument* arg) : Expression(pool, kind) { arg_ = arg; diff --git a/src/common/expression/TypeCastingExpression.h b/src/common/expression/TypeCastingExpression.h index 092b529fb4f..6009dfb7821 100644 --- a/src/common/expression/TypeCastingExpression.h +++ b/src/common/expression/TypeCastingExpression.h @@ -17,7 +17,7 @@ class TypeCastingExpression final : public Expression { static TypeCastingExpression* make(ObjectPool* pool, Value::Type vType = Value::Type::__EMPTY__, Expression* operand = nullptr) { - return pool->add(new TypeCastingExpression(pool, vType, operand)); + return pool->makeAndAdd(pool, vType, operand); } bool operator==(const Expression& rhs) const override; @@ -51,6 +51,7 @@ class TypeCastingExpression final : public Expression { static bool validateTypeCast(Value::Type operandType, Value::Type type); private: + friend ObjectPool; explicit TypeCastingExpression(ObjectPool* pool, Value::Type vType = Value::Type::__EMPTY__, Expression* operand = nullptr) diff --git a/src/common/expression/UUIDExpression.h b/src/common/expression/UUIDExpression.h index febcfc32d6a..1a9c13e8fd2 100644 --- a/src/common/expression/UUIDExpression.h +++ b/src/common/expression/UUIDExpression.h @@ -15,7 +15,7 @@ class UUIDExpression final : public Expression { public: static UUIDExpression* make(ObjectPool* pool) { - return pool->add(new UUIDExpression(pool)); + return pool->makeAndAdd(pool); } bool operator==(const Expression& rhs) const override; @@ -31,6 +31,7 @@ class UUIDExpression final : public Expression { } private: + friend ObjectPool; explicit UUIDExpression(ObjectPool* pool) : Expression(pool, Kind::kUUID) {} void writeTo(Encoder& encoder) const override; diff --git a/src/common/expression/UnaryExpression.h b/src/common/expression/UnaryExpression.h index 26cd28d766a..1883aa0f118 100644 --- a/src/common/expression/UnaryExpression.h +++ b/src/common/expression/UnaryExpression.h @@ -15,39 +15,43 @@ class UnaryExpression final : public Expression { public: static UnaryExpression* makePlus(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kUnaryPlus, operand)); + return pool->makeAndAdd(pool, Kind::kUnaryPlus, operand); } static UnaryExpression* makeNegate(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kUnaryNegate, operand)); + return pool->makeAndAdd(pool, Kind::kUnaryNegate, operand); } static UnaryExpression* makeNot(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kUnaryNot, operand)); + return pool->makeAndAdd(pool, Kind::kUnaryNot, operand); } static UnaryExpression* makeIncr(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kUnaryIncr, operand)); + return pool->makeAndAdd(pool, Kind::kUnaryIncr, operand); } static UnaryExpression* makeDecr(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kUnaryDecr, operand)); + return pool->makeAndAdd(pool, Kind::kUnaryDecr, operand); } static UnaryExpression* makeIsNull(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kIsNull, operand)); + return pool->makeAndAdd(pool, Kind::kIsNull, operand); } static UnaryExpression* makeIsNotNull(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kIsNotNull, operand)); + return pool->makeAndAdd(pool, Kind::kIsNotNull, operand); } static UnaryExpression* makeIsEmpty(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kIsEmpty, operand)); + return pool->makeAndAdd(pool, Kind::kIsEmpty, operand); } static UnaryExpression* makeIsNotEmpty(ObjectPool* pool, Expression* operand = nullptr) { - return pool->add(new UnaryExpression(pool, Kind::kIsNotEmpty, operand)); + return pool->makeAndAdd(pool, Kind::kIsNotEmpty, operand); + } + + static UnaryExpression* make(ObjectPool* pool, Kind kind, Expression* operand = nullptr) { + return pool->makeAndAdd(pool, kind, operand); } bool operator==(const Expression& rhs) const override; @@ -59,7 +63,7 @@ class UnaryExpression final : public Expression { void accept(ExprVisitor* visitor) override; Expression* clone() const override { - return pool_->add(new UnaryExpression(pool_, kind(), operand_->clone())); + return UnaryExpression::make(pool_, kind(), operand_->clone()); } const Expression* operand() const { @@ -75,6 +79,7 @@ class UnaryExpression final : public Expression { } private: + friend ObjectPool; UnaryExpression(ObjectPool* pool, Kind kind, Expression* operand = nullptr) : Expression(pool, kind), operand_(operand) {} diff --git a/src/common/expression/VariableExpression.h b/src/common/expression/VariableExpression.h index e2b4e03d83d..6df528bd7ba 100644 --- a/src/common/expression/VariableExpression.h +++ b/src/common/expression/VariableExpression.h @@ -14,7 +14,7 @@ class VariableExpression final : public Expression { static VariableExpression* make(ObjectPool* pool, const std::string& var = "", bool isInner = false) { - return pool->add(new VariableExpression(pool, var, isInner)); + return pool->makeAndAdd(pool, var, isInner); } const std::string& var() const { @@ -43,6 +43,7 @@ class VariableExpression final : public Expression { } private: + friend ObjectPool; explicit VariableExpression(ObjectPool* pool, const std::string& var = "", bool isInner = false) : Expression(pool, Kind::kVar), isInner_(isInner), var_(var) {} @@ -63,7 +64,7 @@ class VersionedVariableExpression final : public Expression { static VersionedVariableExpression* make(ObjectPool* pool, const std::string& var = "", Expression* version = nullptr) { - return pool->add(new VersionedVariableExpression(pool, var, version)); + return pool->makeAndAdd(pool, var, version); } const std::string& var() const { @@ -94,6 +95,7 @@ class VersionedVariableExpression final : public Expression { } private: + friend ObjectPool; explicit VersionedVariableExpression(ObjectPool* pool, const std::string& var = "", Expression* version = nullptr) diff --git a/src/common/expression/VertexExpression.h b/src/common/expression/VertexExpression.h index 29dd45806a3..e3d8e5b22da 100644 --- a/src/common/expression/VertexExpression.h +++ b/src/common/expression/VertexExpression.h @@ -21,7 +21,7 @@ class VertexExpression final : public Expression { // default name : VERTEX, $^ : startNode of EDGE, $$ : endNode of EDGE // $$ & $^ only used in go sentence static VertexExpression *make(ObjectPool *pool, const std::string &name = "VERTEX") { - return pool->add(new VertexExpression(pool, name)); + return pool->makeAndAdd(pool, name); } const Value &eval(ExpressionContext &ctx) override; @@ -43,6 +43,7 @@ class VertexExpression final : public Expression { bool operator==(const Expression &expr) const override; private: + friend ObjectPool; VertexExpression(ObjectPool *pool, const std::string &name) : Expression(pool, Kind::kVertex), name_(name) {} diff --git a/src/graph/executor/Executor.cpp b/src/graph/executor/Executor.cpp index 6e1a5ae6ddf..292fd0842f2 100644 --- a/src/graph/executor/Executor.cpp +++ b/src/graph/executor/Executor.cpp @@ -154,7 +154,7 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { auto &spaceName = qctx->rctx() ? qctx->rctx()->session()->spaceName() : ""; switch (node->kind()) { case PlanNode::Kind::kPassThrough: { - return pool->add(new PassThroughExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAggregate: { stats::StatsManager::addValue(kNumAggregateExecutors); @@ -162,7 +162,7 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { stats::StatsManager::addValue( stats::StatsManager::counterWithLabels(kNumAggregateExecutors, {{"space", spaceName}})); } - return pool->add(new AggregateExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSort: { stats::StatsManager::addValue(kNumSortExecutors); @@ -170,40 +170,40 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { stats::StatsManager::addValue( stats::StatsManager::counterWithLabels(kNumSortExecutors, {{"space", spaceName}})); } - return pool->add(new SortExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kTopN: { - return pool->add(new TopNExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kFilter: { - return pool->add(new FilterExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kGetEdges: { - return pool->add(new GetEdgesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kGetVertices: { - return pool->add(new GetVerticesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kScanEdges: { - return pool->add(new ScanEdgesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kScanVertices: { - return pool->add(new ScanVerticesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kGetNeighbors: { - return pool->add(new GetNeighborsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kLimit: { - return pool->add(new LimitExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSample: { - return pool->add(new SampleExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kProject: { - return pool->add(new ProjectExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUnwind: { - return pool->add(new UnwindExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kIndexScan: case PlanNode::Kind::kEdgeIndexFullScan: @@ -217,337 +217,337 @@ Executor *Executor::makeExecutor(QueryContext *qctx, const PlanNode *node) { stats::StatsManager::addValue( stats::StatsManager::counterWithLabels(kNumIndexScanExecutors, {{"space", spaceName}})); } - return pool->add(new IndexScanExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kStart: { - return pool->add(new StartExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUnion: { - return pool->add(new UnionExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUnionAllVersionVar: { - return pool->add(new UnionAllVersionVarExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kIntersect: { - return pool->add(new IntersectExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kMinus: { - return pool->add(new MinusExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kLoop: { - return pool->add(new LoopExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSelect: { - return pool->add(new SelectExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDedup: { - return pool->add(new DedupExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAssign: { - return pool->add(new AssignExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSwitchSpace: { - return pool->add(new SwitchSpaceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateSpace: { - return pool->add(new CreateSpaceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateSpaceAs: { - return pool->add(new CreateSpaceAsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDescSpace: { - return pool->add(new DescSpaceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowSpaces: { - return pool->add(new ShowSpacesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropSpace: { - return pool->add(new DropSpaceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kClearSpace: { - return pool->add(new ClearSpaceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowCreateSpace: { - return pool->add(new ShowCreateSpaceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateTag: { - return pool->add(new CreateTagExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDescTag: { - return pool->add(new DescTagExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAlterTag: { - return pool->add(new AlterTagExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateEdge: { - return pool->add(new CreateEdgeExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDescEdge: { - return pool->add(new DescEdgeExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAlterEdge: { - return pool->add(new AlterEdgeExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowTags: { - return pool->add(new ShowTagsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowEdges: { - return pool->add(new ShowEdgesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropTag: { - return pool->add(new DropTagExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropEdge: { - return pool->add(new DropEdgeExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowCreateTag: { - return pool->add(new ShowCreateTagExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowCreateEdge: { - return pool->add(new ShowCreateEdgeExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateTagIndex: { - return pool->add(new CreateTagIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateEdgeIndex: { - return pool->add(new CreateEdgeIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateFTIndex: { - return pool->add(new CreateFTIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropTagIndex: { - return pool->add(new DropTagIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropEdgeIndex: { - return pool->add(new DropEdgeIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropFTIndex: { - return pool->add(new DropFTIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDescTagIndex: { - return pool->add(new DescTagIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDescEdgeIndex: { - return pool->add(new DescEdgeIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowCreateTagIndex: { - return pool->add(new ShowCreateTagIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowCreateEdgeIndex: { - return pool->add(new ShowCreateEdgeIndexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowTagIndexes: { - return pool->add(new ShowTagIndexesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowEdgeIndexes: { - return pool->add(new ShowEdgeIndexesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowTagIndexStatus: { - return pool->add(new ShowTagIndexStatusExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowEdgeIndexStatus: { - return pool->add(new ShowEdgeIndexStatusExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kInsertVertices: { - return pool->add(new InsertVerticesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kInsertEdges: { - return pool->add(new InsertEdgesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDataCollect: { - return pool->add(new DataCollectExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateSnapshot: { - return pool->add(new CreateSnapshotExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropSnapshot: { - return pool->add(new DropSnapshotExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowSnapshots: { - return pool->add(new ShowSnapshotsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kLeftJoin: { - return pool->add(new LeftJoinExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kInnerJoin: { - return pool->add(new InnerJoinExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDeleteVertices: { - return pool->add(new DeleteVerticesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDeleteTags: { - return pool->add(new DeleteTagsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDeleteEdges: { - return pool->add(new DeleteEdgesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUpdateVertex: { - return pool->add(new UpdateVertexExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUpdateEdge: { - return pool->add(new UpdateEdgeExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCreateUser: { - return pool->add(new CreateUserExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropUser: { - return pool->add(new DropUserExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUpdateUser: { - return pool->add(new UpdateUserExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kGrantRole: { - return pool->add(new GrantRoleExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kRevokeRole: { - return pool->add(new RevokeRoleExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kChangePassword: { - return pool->add(new ChangePasswordExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kListUserRoles: { - return pool->add(new ListUserRolesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kListUsers: { - return pool->add(new ListUsersExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kListRoles: { - return pool->add(new ListRolesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDescribeUser: { - return pool->add(new DescribeUserExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowConfigs: { - return pool->add(new ShowConfigsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSetConfig: { - return pool->add(new SetConfigExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kGetConfig: { - return pool->add(new GetConfigExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSubmitJob: { - return pool->add(new SubmitJobExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowHosts: { - return pool->add(new ShowHostsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowMetaLeader: { - return pool->add(new ShowMetaLeaderExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowParts: { - return pool->add(new ShowPartsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowCharset: { - return pool->add(new ShowCharsetExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowCollation: { - return pool->add(new ShowCollationExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kBFSShortest: { - return pool->add(new BFSShortestPathExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kMultiShortestPath: { - return pool->add(new MultiShortestPathExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kProduceAllPaths: { - return pool->add(new ProduceAllPathsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kCartesianProduct: { - return pool->add(new CartesianProductExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSubgraph: { - return pool->add(new SubgraphExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAddHosts: { - return pool->add(new AddHostsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropHosts: { - return pool->add(new DropHostsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kMergeZone: { - return pool->add(new MergeZoneExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kRenameZone: { - return pool->add(new RenameZoneExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDropZone: { - return pool->add(new DropZoneExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDivideZone: { - return pool->add(new DivideZoneExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kDescribeZone: { - return pool->add(new DescribeZoneExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAddHostsIntoZone: { - return pool->add(new AddHostsIntoZoneExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowZones: { - return pool->add(new ListZonesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAddListener: { - return pool->add(new AddListenerExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kRemoveListener: { - return pool->add(new RemoveListenerExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowListener: { - return pool->add(new ShowListenerExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowStats: { - return pool->add(new ShowStatsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowServiceClients: { - return pool->add(new ShowServiceClientsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowFTIndexes: { - return pool->add(new ShowFTIndexesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSignInService: { - return pool->add(new SignInServiceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kSignOutService: { - return pool->add(new SignOutServiceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowSessions: { - return pool->add(new ShowSessionsExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUpdateSession: { - return pool->add(new UpdateSessionExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShowQueries: { - return pool->add(new ShowQueriesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kKillQuery: { - return pool->add(new KillQueryExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kTraverse: { - return pool->add(new TraverseExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAppendVertices: { - return pool->add(new AppendVerticesExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kBiLeftJoin: { - return pool->add(new BiLeftJoinExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kBiInnerJoin: { - return pool->add(new BiInnerJoinExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kBiCartesianProduct: { - return pool->add(new BiCartesianProductExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kRollUpApply: { - return pool->add(new RollUpApplyExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kArgument: { - return pool->add(new ArgumentExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kAlterSpace: { - return pool->add(new AlterSpaceExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kShortestPath: { - return pool->add(new ShortestPathExecutor(node, qctx)); + return pool->makeAndAdd(node, qctx); } case PlanNode::Kind::kUnknown: { LOG(FATAL) << "Unknown plan node kind " << static_cast(node->kind()); diff --git a/src/graph/optimizer/OptGroup.cpp b/src/graph/optimizer/OptGroup.cpp index 40ebea88a53..955b7031e0c 100644 --- a/src/graph/optimizer/OptGroup.cpp +++ b/src/graph/optimizer/OptGroup.cpp @@ -24,7 +24,7 @@ namespace nebula { namespace opt { OptGroup *OptGroup::create(OptContext *ctx) { - return ctx->objPool()->add(new OptGroup(ctx)); + return ctx->objPool()->makeAndAdd(ctx); } void OptGroup::setUnexplored(const OptRule *rule) { @@ -161,7 +161,7 @@ const PlanNode *OptGroup::getPlan() const { } OptGroupNode *OptGroupNode::create(OptContext *ctx, PlanNode *node, const OptGroup *group) { - auto optGNode = ctx->objPool()->add(new OptGroupNode(node, group)); + auto optGNode = ctx->objPool()->makeAndAdd(node, group); ctx->addPlanNodeAndOptGroupNode(node->id(), optGNode); return optGNode; } diff --git a/src/graph/optimizer/OptGroup.h b/src/graph/optimizer/OptGroup.h index 04ec946a4aa..276bcc75bb8 100644 --- a/src/graph/optimizer/OptGroup.h +++ b/src/graph/optimizer/OptGroup.h @@ -6,6 +6,7 @@ #ifndef GRAPH_OPTIMIZER_OPTGROUP_H_ #define GRAPH_OPTIMIZER_OPTGROUP_H_ +#include "common/base/ObjectPool.h" #include "common/base/Status.h" namespace nebula { @@ -48,6 +49,7 @@ class OptGroup final { } private: + friend ObjectPool; explicit OptGroup(OptContext *ctx) noexcept; static constexpr int16_t kMaxExplorationRound = 128; @@ -108,6 +110,7 @@ class OptGroupNode final { const graph::PlanNode *getPlan() const; private: + friend ObjectPool; OptGroupNode(graph::PlanNode *node, const OptGroup *group) noexcept; graph::PlanNode *node_{nullptr}; diff --git a/src/graph/planner/match/MatchSolver.cpp b/src/graph/planner/match/MatchSolver.cpp index 16d33439df5..b1c5b95c6f1 100644 --- a/src/graph/planner/match/MatchSolver.cpp +++ b/src/graph/planner/match/MatchSolver.cpp @@ -218,7 +218,7 @@ void MatchSolver::extractAndDedupVidColumn(QueryContext* qctx, PlanNode* dep, const std::string& inputVar, SubPlan& plan) { - auto columns = qctx->objPool()->add(new YieldColumns); + auto columns = qctx->objPool()->makeAndAdd(); auto* var = qctx->symTable()->getVar(inputVar); Expression* vidExpr = initialExprOrEdgeDstExpr(qctx, initialExpr, var->colNames.back()); if (initialExpr) { @@ -312,7 +312,7 @@ Status MatchSolver::appendFetchVertexPlan(const Expression* nodeFilter, } // Normalize all columns to one - auto columns = pool->add(new YieldColumns); + auto columns = pool->makeAndAdd(); auto pathExpr = PathBuildExpression::make(pool); pathExpr->add(VertexExpression::make(pool)); columns->addColumn(new YieldColumn(pathExpr)); diff --git a/src/graph/planner/match/YieldClausePlanner.cpp b/src/graph/planner/match/YieldClausePlanner.cpp index bc500125b61..1c3f1df33c6 100644 --- a/src/graph/planner/match/YieldClausePlanner.cpp +++ b/src/graph/planner/match/YieldClausePlanner.cpp @@ -45,7 +45,7 @@ void YieldClausePlanner::rewriteGroupExprs(const YieldClauseContext* yctx, Status YieldClausePlanner::buildYield(YieldClauseContext* yctx, SubPlan& subplan) { auto* currentRoot = subplan.root; DCHECK(!currentRoot); - auto* newProjCols = yctx->qctx->objPool()->add(new YieldColumns()); + auto* newProjCols = yctx->qctx->objPool()->makeAndAdd(); rewriteYieldColumns(yctx, yctx->projCols_, newProjCols); if (!yctx->hasAgg_) { auto* project = Project::make(yctx->qctx, currentRoot, newProjCols); diff --git a/src/graph/planner/ngql/GoPlanner.cpp b/src/graph/planner/ngql/GoPlanner.cpp index 8f7215b7bb0..afc95df18a7 100644 --- a/src/graph/planner/ngql/GoPlanner.cpp +++ b/src/graph/planner/ngql/GoPlanner.cpp @@ -118,7 +118,7 @@ PlanNode* GoPlanner::extractSrcEdgePropsFromGN(PlanNode* dep, const std::string& PlanNode* GoPlanner::extractSrcDstFromGN(PlanNode* dep, const std::string& input) { auto qctx = goCtx_->qctx; auto* pool = qctx->objPool(); - auto* columns = pool->add(new YieldColumns()); + auto* columns = pool->makeAndAdd(); goCtx_->srcVidColName = qctx->vctx()->anonColGen()->getCol(); auto* vidExpr = new YieldColumn(ColumnExpression::make(pool, VID_INDEX), goCtx_->srcVidColName); @@ -141,7 +141,7 @@ PlanNode* GoPlanner::extractVidFromRuntimeInput(PlanNode* dep) { auto qctx = goCtx_->qctx; const auto& from = goCtx_->from; - auto* columns = qctx->objPool()->add(new YieldColumns()); + auto* columns = qctx->objPool()->makeAndAdd(); auto* vidExpr = new YieldColumn(from.originalSrc->clone(), from.runtimeVidName); columns->addColumn(vidExpr); @@ -181,7 +181,7 @@ PlanNode* GoPlanner::trackStartVid(PlanNode* left, PlanNode* right) { join->setColNames(std::move(colNames)); // extract runtimeVid & dst from join result - auto* columns = pool->add(new YieldColumns()); + auto* columns = pool->makeAndAdd(); auto& vidName = goCtx_->from.runtimeVidName; auto* vidExpr = new YieldColumn(InputPropertyExpression::make(pool, vidName), vidName); columns->addColumn(vidExpr); diff --git a/src/graph/planner/ngql/PathPlanner.cpp b/src/graph/planner/ngql/PathPlanner.cpp index 9228640d768..8b20c266f3b 100644 --- a/src/graph/planner/ngql/PathPlanner.cpp +++ b/src/graph/planner/ngql/PathPlanner.cpp @@ -182,7 +182,7 @@ SubPlan PathPlanner::loopDepPlan() { auto* pool = qctx->objPool(); SubPlan subPlan = buildRuntimeVidPlan(); { - auto* columns = pool->add(new YieldColumns()); + auto* columns = pool->makeAndAdd(); auto* column = new YieldColumn(ColumnExpression::make(pool, 0), kVid); columns->addColumn(column); auto* project = Project::make(qctx, subPlan.root, columns); @@ -193,7 +193,7 @@ SubPlan PathPlanner::loopDepPlan() { } subPlan.tail = subPlan.tail == nullptr ? subPlan.root : subPlan.tail; { - auto* columns = pool->add(new YieldColumns()); + auto* columns = pool->makeAndAdd(); auto* column = new YieldColumn(ColumnExpression::make(pool, 0), kVid); columns->addColumn(column); auto* project = Project::make(qctx, subPlan.root, columns); @@ -312,7 +312,7 @@ PlanNode* PathPlanner::buildVertexPlan(PlanNode* dep, const std::string& input) auto funNodes = FunctionCallExpression::make(pool, "nodes", args); auto* column = new YieldColumn(funNodes, "nodes"); - auto* columns = pool->add(new YieldColumns()); + auto* columns = pool->makeAndAdd(); columns->addColumn(column); auto* project = Project::make(qctx, dep, columns); @@ -345,7 +345,7 @@ PlanNode* PathPlanner::buildEdgePlan(PlanNode* dep, const std::string& input) { auto funEdges = FunctionCallExpression::make(pool, "relationships", args); auto* column = new YieldColumn(funEdges, "edges"); - auto* columns = pool->add(new YieldColumns()); + auto* columns = pool->makeAndAdd(); columns->addColumn(column); auto* project = Project::make(qctx, dep, columns); diff --git a/src/graph/planner/plan/Admin.h b/src/graph/planner/plan/Admin.h index 3b390a47f16..bf3490d86a1 100644 --- a/src/graph/planner/plan/Admin.h +++ b/src/graph/planner/plan/Admin.h @@ -54,7 +54,7 @@ class DropNode : public SingleDependencyNode { class AddHosts final : public SingleDependencyNode { public: static AddHosts* make(QueryContext* qctx, PlanNode* dep, std::vector hosts) { - return qctx->objPool()->add(new AddHosts(qctx, dep, hosts)); + return qctx->objPool()->makeAndAdd(qctx, dep, hosts); } std::vector getHosts() const { @@ -64,6 +64,7 @@ class AddHosts final : public SingleDependencyNode { std::unique_ptr explain() const override; private: + friend ObjectPool; AddHosts(QueryContext* qctx, PlanNode* dep, std::vector hosts) : SingleDependencyNode(qctx, Kind::kAddHosts, dep), hosts_(hosts) {} @@ -73,7 +74,7 @@ class AddHosts final : public SingleDependencyNode { class DropHosts final : public SingleDependencyNode { public: static DropHosts* make(QueryContext* qctx, PlanNode* dep, std::vector hosts) { - return qctx->objPool()->add(new DropHosts(qctx, dep, hosts)); + return qctx->objPool()->makeAndAdd(qctx, dep, hosts); } std::vector getHosts() const { @@ -83,6 +84,7 @@ class DropHosts final : public SingleDependencyNode { std::unique_ptr explain() const override; private: + friend ObjectPool; DropHosts(QueryContext* qctx, PlanNode* dep, std::vector hosts) : SingleDependencyNode(qctx, Kind::kDropHosts, dep), hosts_(hosts) {} @@ -93,7 +95,7 @@ class ShowHosts final : public SingleDependencyNode { // TODO(shylock) meta/storage/graph/agent enumerate public: static ShowHosts* make(QueryContext* qctx, PlanNode* dep, meta::cpp2::ListHostType type) { - return qctx->objPool()->add(new ShowHosts(qctx, dep, type)); + return qctx->objPool()->makeAndAdd(qctx, dep, type); } meta::cpp2::ListHostType getType() const { @@ -101,6 +103,7 @@ class ShowHosts final : public SingleDependencyNode { } private: + friend ObjectPool; ShowHosts(QueryContext* qctx, PlanNode* dep, meta::cpp2::ListHostType type) : SingleDependencyNode(qctx, Kind::kShowHosts, dep), type_(type) {} meta::cpp2::ListHostType type_; @@ -109,10 +112,11 @@ class ShowHosts final : public SingleDependencyNode { class ShowMetaLeaderNode final : public SingleDependencyNode { public: static ShowMetaLeaderNode* make(QueryContext* qctx, PlanNode* dep) { - return qctx->objPool()->add(new ShowMetaLeaderNode(qctx, dep)); + return qctx->objPool()->makeAndAdd(qctx, dep); } private: + friend ObjectPool; ShowMetaLeaderNode(QueryContext* qctx, PlanNode* dep) : SingleDependencyNode(qctx, Kind::kShowMetaLeader, dep) {} }; @@ -123,7 +127,7 @@ class CreateSpace final : public SingleDependencyNode { PlanNode* input, meta::cpp2::SpaceDesc spaceDesc, bool ifNotExists) { - return qctx->objPool()->add(new CreateSpace(qctx, input, std::move(spaceDesc), ifNotExists)); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(spaceDesc), ifNotExists); } std::unique_ptr explain() const override; @@ -138,6 +142,7 @@ class CreateSpace final : public SingleDependencyNode { } private: + friend ObjectPool; CreateSpace(QueryContext* qctx, PlanNode* input, meta::cpp2::SpaceDesc spaceDesc, @@ -158,7 +163,7 @@ class CreateSpaceAsNode final : public SingleDependencyNode { PlanNode* input, const std::string& oldSpaceName, const std::string& newSpaceName) { - return qctx->objPool()->add(new CreateSpaceAsNode(qctx, input, oldSpaceName, newSpaceName)); + return qctx->objPool()->makeAndAdd(qctx, input, oldSpaceName, newSpaceName); } std::unique_ptr explain() const override; @@ -173,6 +178,7 @@ class CreateSpaceAsNode final : public SingleDependencyNode { } private: + friend ObjectPool; CreateSpaceAsNode(QueryContext* qctx, PlanNode* input, std::string oldName, std::string newName) : SingleDependencyNode(qctx, Kind::kCreateSpaceAs, input), oldSpaceName_(std::move(oldName)), @@ -189,7 +195,7 @@ class DropSpace final : public SingleDependencyNode { PlanNode* input, std::string spaceName, bool ifExists) { - return qctx->objPool()->add(new DropSpace(qctx, input, std::move(spaceName), ifExists)); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(spaceName), ifExists); } std::unique_ptr explain() const override; @@ -203,6 +209,7 @@ class DropSpace final : public SingleDependencyNode { } private: + friend ObjectPool; DropSpace(QueryContext* qctx, PlanNode* input, std::string spaceName, bool ifExists) : SingleDependencyNode(qctx, Kind::kDropSpace, input) { spaceName_ = std::move(spaceName); @@ -220,7 +227,7 @@ class ClearSpace final : public SingleDependencyNode { PlanNode* input, std::string spaceName, bool ifExists) { - return qctx->objPool()->add(new ClearSpace(qctx, input, std::move(spaceName), ifExists)); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(spaceName), ifExists); } std::unique_ptr explain() const override; @@ -234,6 +241,7 @@ class ClearSpace final : public SingleDependencyNode { } private: + friend ObjectPool; ClearSpace(QueryContext* qctx, PlanNode* input, std::string spaceName, bool ifExists) : SingleDependencyNode(qctx, Kind::kClearSpace, input) { spaceName_ = std::move(spaceName); @@ -252,7 +260,7 @@ class AlterSpace final : public SingleDependencyNode { const std::string& spaceName, meta::cpp2::AlterSpaceOp op, const std::vector& paras) { - return qctx->objPool()->add(new AlterSpace(qctx, input, spaceName, op, paras)); + return qctx->objPool()->makeAndAdd(qctx, input, spaceName, op, paras); } const std::string& getSpaceName() const { return spaceName_; @@ -267,6 +275,7 @@ class AlterSpace final : public SingleDependencyNode { } private: + friend ObjectPool; AlterSpace(QueryContext* qctx, PlanNode* input, const std::string& spaceName, @@ -286,7 +295,7 @@ class AlterSpace final : public SingleDependencyNode { class DescSpace final : public SingleDependencyNode { public: static DescSpace* make(QueryContext* qctx, PlanNode* input, std::string spaceName) { - return qctx->objPool()->add(new DescSpace(qctx, input, std::move(spaceName))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(spaceName)); } std::unique_ptr explain() const override; @@ -296,6 +305,7 @@ class DescSpace final : public SingleDependencyNode { } private: + friend ObjectPool; DescSpace(QueryContext* qctx, PlanNode* input, std::string spaceName) : SingleDependencyNode(qctx, Kind::kDescSpace, input) { spaceName_ = std::move(spaceName); @@ -308,10 +318,11 @@ class DescSpace final : public SingleDependencyNode { class ShowSpaces final : public SingleDependencyNode { public: static ShowSpaces* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ShowSpaces(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ShowSpaces(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowSpaces, input) {} }; @@ -319,7 +330,7 @@ class ShowSpaces final : public SingleDependencyNode { class ShowConfigs final : public SingleDependencyNode { public: static ShowConfigs* make(QueryContext* qctx, PlanNode* input, meta::cpp2::ConfigModule module) { - return qctx->objPool()->add(new ShowConfigs(qctx, input, module)); + return qctx->objPool()->makeAndAdd(qctx, input, module); } std::unique_ptr explain() const override; @@ -329,6 +340,7 @@ class ShowConfigs final : public SingleDependencyNode { } private: + friend ObjectPool; ShowConfigs(QueryContext* qctx, PlanNode* input, meta::cpp2::ConfigModule module) : SingleDependencyNode(qctx, Kind::kShowConfigs, input), module_(module) {} @@ -343,8 +355,8 @@ class SetConfig final : public SingleDependencyNode { meta::cpp2::ConfigModule module, std::string name, Value value) { - return qctx->objPool()->add( - new SetConfig(qctx, input, module, std::move(name), std::move(value))); + return qctx->objPool()->makeAndAdd( + qctx, input, module, std::move(name), std::move(value)); } std::unique_ptr explain() const override; @@ -362,6 +374,7 @@ class SetConfig final : public SingleDependencyNode { } private: + friend ObjectPool; SetConfig(QueryContext* qctx, PlanNode* input, meta::cpp2::ConfigModule module, @@ -384,7 +397,7 @@ class GetConfig final : public SingleDependencyNode { PlanNode* input, meta::cpp2::ConfigModule module, std::string name) { - return qctx->objPool()->add(new GetConfig(qctx, input, module, std::move(name))); + return qctx->objPool()->makeAndAdd(qctx, input, module, std::move(name)); } std::unique_ptr explain() const override; @@ -398,6 +411,7 @@ class GetConfig final : public SingleDependencyNode { } private: + friend ObjectPool; GetConfig(QueryContext* qctx, PlanNode* input, meta::cpp2::ConfigModule module, std::string name) : SingleDependencyNode(qctx, Kind::kGetConfig, input), module_(module), @@ -411,7 +425,7 @@ class GetConfig final : public SingleDependencyNode { class ShowCreateSpace final : public SingleDependencyNode { public: static ShowCreateSpace* make(QueryContext* qctx, PlanNode* input, std::string spaceName) { - return qctx->objPool()->add(new ShowCreateSpace(qctx, input, std::move(spaceName))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(spaceName)); } std::unique_ptr explain() const override; @@ -421,6 +435,7 @@ class ShowCreateSpace final : public SingleDependencyNode { } private: + friend ObjectPool; ShowCreateSpace(QueryContext* qctx, PlanNode* input, std::string spaceName) : SingleDependencyNode(qctx, Kind::kShowCreateSpace, input) { spaceName_ = std::move(spaceName); @@ -433,10 +448,11 @@ class ShowCreateSpace final : public SingleDependencyNode { class CreateSnapshot final : public SingleDependencyNode { public: static CreateSnapshot* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new CreateSnapshot(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; CreateSnapshot(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kCreateSnapshot, input) {} }; @@ -444,7 +460,7 @@ class CreateSnapshot final : public SingleDependencyNode { class DropSnapshot final : public SingleDependencyNode { public: static DropSnapshot* make(QueryContext* qctx, PlanNode* input, std::string snapshotName) { - return qctx->objPool()->add(new DropSnapshot(qctx, input, std::move(snapshotName))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(snapshotName)); } std::unique_ptr explain() const override; @@ -454,6 +470,7 @@ class DropSnapshot final : public SingleDependencyNode { } private: + friend ObjectPool; DropSnapshot(QueryContext* qctx, PlanNode* input, std::string snapshotName) : SingleDependencyNode(qctx, Kind::kDropSnapshot, input) { snapshotName_ = std::move(snapshotName); @@ -466,10 +483,11 @@ class DropSnapshot final : public SingleDependencyNode { class ShowSnapshots final : public SingleDependencyNode { public: static ShowSnapshots* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ShowSnapshots(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ShowSnapshots(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowSnapshots, input) {} }; @@ -480,7 +498,7 @@ class AddListener final : public SingleDependencyNode { PlanNode* input, meta::cpp2::ListenerType type, std::vector hosts) { - return qctx->objPool()->add(new AddListener(qctx, input, std::move(type), std::move(hosts))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(type), std::move(hosts)); } const meta::cpp2::ListenerType& type() const { @@ -492,6 +510,7 @@ class AddListener final : public SingleDependencyNode { } private: + friend ObjectPool; AddListener(QueryContext* qctx, PlanNode* input, meta::cpp2::ListenerType type, @@ -509,7 +528,7 @@ class AddListener final : public SingleDependencyNode { class RemoveListener final : public SingleDependencyNode { public: static RemoveListener* make(QueryContext* qctx, PlanNode* input, meta::cpp2::ListenerType type) { - return qctx->objPool()->add(new RemoveListener(qctx, input, std::move(type))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(type)); } const meta::cpp2::ListenerType& type() const { @@ -517,6 +536,7 @@ class RemoveListener final : public SingleDependencyNode { } private: + friend ObjectPool; RemoveListener(QueryContext* qctx, PlanNode* input, meta::cpp2::ListenerType type) : SingleDependencyNode(qctx, Kind::kRemoveListener, input) { type_ = std::move(type); @@ -529,10 +549,11 @@ class RemoveListener final : public SingleDependencyNode { class ShowListener final : public SingleDependencyNode { public: static ShowListener* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ShowListener(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ShowListener(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowListener, input) {} }; @@ -545,7 +566,7 @@ class CreateUser final : public CreateNode { const std::string* username, const std::string* password, bool ifNotExists) { - return qctx->objPool()->add(new CreateUser(qctx, dep, username, password, ifNotExists)); + return qctx->objPool()->makeAndAdd(qctx, dep, username, password, ifNotExists); } std::unique_ptr explain() const override; @@ -559,6 +580,7 @@ class CreateUser final : public CreateNode { } private: + friend ObjectPool; CreateUser(QueryContext* qctx, PlanNode* dep, const std::string* username, @@ -579,7 +601,7 @@ class DropUser final : public DropNode { PlanNode* dep, const std::string* username, bool ifNotExists) { - return qctx->objPool()->add(new DropUser(qctx, dep, username, ifNotExists)); + return qctx->objPool()->makeAndAdd(qctx, dep, username, ifNotExists); } std::unique_ptr explain() const override; @@ -589,6 +611,7 @@ class DropUser final : public DropNode { } private: + friend ObjectPool; DropUser(QueryContext* qctx, PlanNode* dep, const std::string* username, bool ifNotExists) : DropNode(qctx, Kind::kDropUser, dep, ifNotExists), username_(username) {} @@ -602,7 +625,7 @@ class UpdateUser final : public SingleDependencyNode { PlanNode* dep, const std::string* username, const std::string* password) { - return qctx->objPool()->add(new UpdateUser(qctx, dep, username, password)); + return qctx->objPool()->makeAndAdd(qctx, dep, username, password); } std::unique_ptr explain() const override; @@ -616,6 +639,7 @@ class UpdateUser final : public SingleDependencyNode { } private: + friend ObjectPool; UpdateUser(QueryContext* qctx, PlanNode* dep, const std::string* username, @@ -636,7 +660,7 @@ class GrantRole final : public SingleDependencyNode { const std::string* username, const std::string* spaceName, meta::cpp2::RoleType role) { - return qctx->objPool()->add(new GrantRole(qctx, dep, username, spaceName, role)); + return qctx->objPool()->makeAndAdd(qctx, dep, username, spaceName, role); } std::unique_ptr explain() const override; @@ -654,6 +678,7 @@ class GrantRole final : public SingleDependencyNode { } private: + friend ObjectPool; GrantRole(QueryContext* qctx, PlanNode* dep, const std::string* username, @@ -677,7 +702,7 @@ class RevokeRole final : public SingleDependencyNode { const std::string* username, const std::string* spaceName, meta::cpp2::RoleType role) { - return qctx->objPool()->add(new RevokeRole(qctx, dep, username, spaceName, role)); + return qctx->objPool()->makeAndAdd(qctx, dep, username, spaceName, role); } std::unique_ptr explain() const override; @@ -695,6 +720,7 @@ class RevokeRole final : public SingleDependencyNode { } private: + friend ObjectPool; RevokeRole(QueryContext* qctx, PlanNode* dep, const std::string* username, @@ -718,7 +744,7 @@ class ChangePassword final : public SingleDependencyNode { const std::string* username, const std::string* password, const std::string* newPassword) { - return qctx->objPool()->add(new ChangePassword(qctx, dep, username, password, newPassword)); + return qctx->objPool()->makeAndAdd(qctx, dep, username, password, newPassword); } std::unique_ptr explain() const override; @@ -736,6 +762,7 @@ class ChangePassword final : public SingleDependencyNode { } private: + friend ObjectPool; ChangePassword(QueryContext* qctx, PlanNode* dep, const std::string* username, @@ -755,7 +782,7 @@ class ChangePassword final : public SingleDependencyNode { class ListUserRoles final : public SingleDependencyNode { public: static ListUserRoles* make(QueryContext* qctx, PlanNode* dep, const std::string* username) { - return qctx->objPool()->add(new ListUserRoles(qctx, dep, username)); + return qctx->objPool()->makeAndAdd(qctx, dep, username); } std::unique_ptr explain() const override; @@ -765,6 +792,7 @@ class ListUserRoles final : public SingleDependencyNode { } private: + friend ObjectPool; ListUserRoles(QueryContext* qctx, PlanNode* dep, const std::string* username) : SingleDependencyNode(qctx, Kind::kListUserRoles, dep), username_(username) {} @@ -775,10 +803,11 @@ class ListUserRoles final : public SingleDependencyNode { class ListUsers final : public SingleDependencyNode { public: static ListUsers* make(QueryContext* qctx, PlanNode* dep) { - return qctx->objPool()->add(new ListUsers(qctx, dep)); + return qctx->objPool()->makeAndAdd(qctx, dep); } private: + friend ObjectPool; ListUsers(QueryContext* qctx, PlanNode* dep) : SingleDependencyNode(qctx, Kind::kListUsers, dep) {} }; @@ -786,7 +815,7 @@ class ListUsers final : public SingleDependencyNode { class DescribeUser final : public SingleDependencyNode { public: static DescribeUser* make(QueryContext* qctx, PlanNode* dep, const std::string* username) { - return qctx->objPool()->add(new DescribeUser(qctx, dep, username)); + return qctx->objPool()->makeAndAdd(qctx, dep, username); } std::unique_ptr explain() const override; @@ -796,6 +825,7 @@ class DescribeUser final : public SingleDependencyNode { } private: + friend ObjectPool; DescribeUser(QueryContext* qctx, PlanNode* dep, const std::string* username) : SingleDependencyNode(qctx, Kind::kDescribeUser, dep), username_(username) {} @@ -805,7 +835,7 @@ class DescribeUser final : public SingleDependencyNode { class ListRoles final : public SingleDependencyNode { public: static ListRoles* make(QueryContext* qctx, PlanNode* dep, GraphSpaceID space) { - return qctx->objPool()->add(new ListRoles(qctx, dep, space)); + return qctx->objPool()->makeAndAdd(qctx, dep, space); } std::unique_ptr explain() const override; @@ -815,6 +845,7 @@ class ListRoles final : public SingleDependencyNode { } private: + friend ObjectPool; ListRoles(QueryContext* qctx, PlanNode* dep, GraphSpaceID space) : SingleDependencyNode(qctx, Kind::kListRoles, dep), space_(space) {} @@ -827,7 +858,7 @@ class ShowParts final : public SingleDependencyNode { PlanNode* input, GraphSpaceID spaceId, std::vector partIds) { - return qctx->objPool()->add(new ShowParts(qctx, input, spaceId, std::move(partIds))); + return qctx->objPool()->makeAndAdd(qctx, input, spaceId, std::move(partIds)); } std::unique_ptr explain() const override; @@ -851,6 +882,7 @@ class ShowParts final : public SingleDependencyNode { } private: + friend ObjectPool; GraphSpaceID spaceId_{-1}; std::vector partIds_; }; @@ -862,7 +894,7 @@ class SubmitJob final : public SingleDependencyNode { meta::cpp2::JobOp op, meta::cpp2::JobType type, const std::vector& params) { - return qctx->objPool()->add(new SubmitJob(qctx, dep, op, type, params)); + return qctx->objPool()->makeAndAdd(qctx, dep, op, type, params); } std::unique_ptr explain() const override; @@ -881,6 +913,7 @@ class SubmitJob final : public SingleDependencyNode { } private: + friend ObjectPool; SubmitJob(QueryContext* qctx, PlanNode* dep, meta::cpp2::JobOp op, @@ -897,10 +930,11 @@ class SubmitJob final : public SingleDependencyNode { class ShowCharset final : public SingleDependencyNode { public: static ShowCharset* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ShowCharset(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ShowCharset(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowCharset, input) {} }; @@ -908,10 +942,11 @@ class ShowCharset final : public SingleDependencyNode { class ShowCollation final : public SingleDependencyNode { public: static ShowCollation* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ShowCollation(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ShowCollation(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowCollation, input) {} }; @@ -923,8 +958,8 @@ class AddHostsIntoZone final : public SingleDependencyNode { std::string zoneName, std::vector addresses, bool isNew) { - return qctx->objPool()->add( - new AddHostsIntoZone(qctx, input, std::move(zoneName), std::move(addresses), isNew)); + return qctx->objPool()->makeAndAdd( + qctx, input, std::move(zoneName), std::move(addresses), isNew); } const std::string& zoneName() const { @@ -940,6 +975,7 @@ class AddHostsIntoZone final : public SingleDependencyNode { } private: + friend ObjectPool; AddHostsIntoZone(QueryContext* qctx, PlanNode* input, std::string zoneName, @@ -963,8 +999,8 @@ class MergeZone final : public SingleDependencyNode { PlanNode* input, std::string zoneName, std::vector zoneNames) { - return qctx->objPool()->add( - new MergeZone(qctx, input, std::move(zoneName), std::move(zoneNames))); + return qctx->objPool()->makeAndAdd( + qctx, input, std::move(zoneName), std::move(zoneNames)); } const std::string& zoneName() const { @@ -976,6 +1012,7 @@ class MergeZone final : public SingleDependencyNode { } private: + friend ObjectPool; MergeZone(QueryContext* qctx, PlanNode* input, std::string zoneName, @@ -996,8 +1033,8 @@ class RenameZone final : public SingleDependencyNode { PlanNode* input, std::string originalZoneName, std::string zoneName) { - return qctx->objPool()->add( - new RenameZone(qctx, input, std::move(originalZoneName), std::move(zoneName))); + return qctx->objPool()->makeAndAdd( + qctx, input, std::move(originalZoneName), std::move(zoneName)); } const std::string& originalZoneName() const { @@ -1009,6 +1046,7 @@ class RenameZone final : public SingleDependencyNode { } private: + friend ObjectPool; RenameZone(QueryContext* qctx, PlanNode* input, std::string originalZoneName, @@ -1026,7 +1064,7 @@ class RenameZone final : public SingleDependencyNode { class DropZone final : public SingleDependencyNode { public: static DropZone* make(QueryContext* qctx, PlanNode* input, std::string zoneName) { - return qctx->objPool()->add(new DropZone(qctx, input, std::move(zoneName))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(zoneName)); } const std::string& zoneName() const { @@ -1034,6 +1072,7 @@ class DropZone final : public SingleDependencyNode { } private: + friend ObjectPool; DropZone(QueryContext* qctx, PlanNode* input, std::string zoneName) : SingleDependencyNode(qctx, Kind::kDropZone, input) { zoneName_ = std::move(zoneName); @@ -1049,8 +1088,8 @@ class DivideZone final : public SingleDependencyNode { PlanNode* input, std::string zoneName, std::unordered_map> zoneItems) { - return qctx->objPool()->add( - new DivideZone(qctx, input, std::move(zoneName), std::move(zoneItems))); + return qctx->objPool()->makeAndAdd( + qctx, input, std::move(zoneName), std::move(zoneItems)); } const std::string& zoneName() const { @@ -1062,6 +1101,7 @@ class DivideZone final : public SingleDependencyNode { } private: + friend ObjectPool; DivideZone(QueryContext* qctx, PlanNode* input, std::string zoneName, @@ -1079,7 +1119,7 @@ class DivideZone final : public SingleDependencyNode { class DescribeZone final : public SingleDependencyNode { public: static DescribeZone* make(QueryContext* qctx, PlanNode* input, std::string zoneName) { - return qctx->objPool()->add(new DescribeZone(qctx, input, std::move(zoneName))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(zoneName)); } const std::string& zoneName() const { @@ -1087,6 +1127,7 @@ class DescribeZone final : public SingleDependencyNode { } private: + friend ObjectPool; DescribeZone(QueryContext* qctx, PlanNode* input, std::string zoneName) : SingleDependencyNode(qctx, Kind::kDescribeZone, input) { zoneName_ = std::move(zoneName); @@ -1099,10 +1140,11 @@ class DescribeZone final : public SingleDependencyNode { class ListZones final : public SingleDependencyNode { public: static ListZones* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ListZones(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ListZones(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowZones, input) {} }; @@ -1110,10 +1152,11 @@ class ListZones final : public SingleDependencyNode { class ShowZones final : public SingleDependencyNode { public: static ShowZones* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ShowZones(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ShowZones(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowZones, input) {} }; @@ -1121,10 +1164,11 @@ class ShowZones final : public SingleDependencyNode { class ShowStats final : public SingleDependencyNode { public: static ShowStats* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new ShowStats(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } private: + friend ObjectPool; ShowStats(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kShowStats, input) {} }; @@ -1134,7 +1178,7 @@ class ShowServiceClients final : public SingleDependencyNode { static ShowServiceClients* make(QueryContext* qctx, PlanNode* input, meta::cpp2::ExternalServiceType type) { - return qctx->objPool()->add(new ShowServiceClients(qctx, input, type)); + return qctx->objPool()->makeAndAdd(qctx, input, type); } meta::cpp2::ExternalServiceType type() const { @@ -1142,6 +1186,7 @@ class ShowServiceClients final : public SingleDependencyNode { } private: + friend ObjectPool; ShowServiceClients(QueryContext* qctx, PlanNode* input, meta::cpp2::ExternalServiceType type) : SingleDependencyNode(qctx, Kind::kShowServiceClients, input), type_(type) {} @@ -1155,7 +1200,7 @@ class SignInService final : public SingleDependencyNode { PlanNode* input, std::vector clients, meta::cpp2::ExternalServiceType type) { - return qctx->objPool()->add(new SignInService(qctx, input, std::move(clients), type)); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(clients), type); } const std::vector& clients() const { @@ -1167,6 +1212,7 @@ class SignInService final : public SingleDependencyNode { } private: + friend ObjectPool; SignInService(QueryContext* qctx, PlanNode* input, std::vector clients, @@ -1185,7 +1231,7 @@ class SignOutService final : public SingleDependencyNode { static SignOutService* make(QueryContext* qctx, PlanNode* input, meta::cpp2::ExternalServiceType type) { - return qctx->objPool()->add(new SignOutService(qctx, input, type)); + return qctx->objPool()->makeAndAdd(qctx, input, type); } meta::cpp2::ExternalServiceType type() const { @@ -1193,6 +1239,7 @@ class SignOutService final : public SingleDependencyNode { } private: + friend ObjectPool; SignOutService(QueryContext* qctx, PlanNode* input, meta::cpp2::ExternalServiceType type) : SingleDependencyNode(qctx, Kind::kSignOutService, input), type_(type) {} @@ -1207,8 +1254,8 @@ class ShowSessions final : public SingleInputNode { bool isSetSessionID, SessionID sessionId, bool isLocalCommand) { - return qctx->objPool()->add( - new ShowSessions(qctx, input, isSetSessionID, sessionId, isLocalCommand)); + return qctx->objPool()->makeAndAdd( + qctx, input, isSetSessionID, sessionId, isLocalCommand); } bool isSetSessionID() const { @@ -1222,6 +1269,7 @@ class ShowSessions final : public SingleInputNode { } private: + friend ObjectPool; ShowSessions(QueryContext* qctx, PlanNode* input, bool isSetSessionID, @@ -1242,7 +1290,7 @@ class ShowSessions final : public SingleInputNode { class UpdateSession final : public SingleInputNode { public: static UpdateSession* make(QueryContext* qctx, PlanNode* input, meta::cpp2::Session session) { - return qctx->objPool()->add(new UpdateSession(qctx, input, std::move(session))); + return qctx->objPool()->makeAndAdd(qctx, input, std::move(session)); } const meta::cpp2::Session& getSession() const { @@ -1250,6 +1298,7 @@ class UpdateSession final : public SingleInputNode { } private: + friend ObjectPool; UpdateSession(QueryContext* qctx, PlanNode* input, meta::cpp2::Session session) : SingleInputNode(qctx, Kind::kUpdateSession, input), session_(std::move(session)) {} @@ -1260,7 +1309,7 @@ class UpdateSession final : public SingleInputNode { class ShowQueries final : public SingleInputNode { public: static ShowQueries* make(QueryContext* qctx, PlanNode* input, bool isAll) { - return qctx->objPool()->add(new ShowQueries(qctx, input, isAll)); + return qctx->objPool()->makeAndAdd(qctx, input, isAll); } bool isAll() const { @@ -1270,6 +1319,7 @@ class ShowQueries final : public SingleInputNode { std::unique_ptr explain() const override; private: + friend ObjectPool; ShowQueries(QueryContext* qctx, PlanNode* input, bool isAll) : SingleInputNode(qctx, Kind::kShowQueries, input), isAll_(isAll) {} @@ -1282,7 +1332,7 @@ class KillQuery final : public SingleInputNode { PlanNode* input, Expression* sessionId, Expression* epId) { - return qctx->objPool()->add(new KillQuery(qctx, input, sessionId, epId)); + return qctx->objPool()->makeAndAdd(qctx, input, sessionId, epId); } Expression* sessionId() const { @@ -1296,6 +1346,7 @@ class KillQuery final : public SingleInputNode { std::unique_ptr explain() const override; private: + friend ObjectPool; KillQuery(QueryContext* qctx, PlanNode* input, Expression* sessionId, Expression* epId) : SingleInputNode(qctx, Kind::kKillQuery, input), sessionId_(sessionId), epId_(epId) {} diff --git a/src/graph/planner/plan/Algo.h b/src/graph/planner/plan/Algo.h index 6b00d6f3e0e..68ae9bee51a 100644 --- a/src/graph/planner/plan/Algo.h +++ b/src/graph/planner/plan/Algo.h @@ -17,7 +17,7 @@ class MultiShortestPath : public BinaryInputNode { PlanNode* left, PlanNode* right, size_t steps) { - return qctx->objPool()->add(new MultiShortestPath(qctx, left, right, steps)); + return qctx->objPool()->makeAndAdd(qctx, left, right, steps); } size_t steps() const { @@ -51,6 +51,7 @@ class MultiShortestPath : public BinaryInputNode { std::unique_ptr explain() const override; private: + friend ObjectPool; MultiShortestPath(QueryContext* qctx, PlanNode* left, PlanNode* right, size_t steps) : BinaryInputNode(qctx, Kind::kMultiShortestPath, left, right), steps_(steps) {} @@ -64,7 +65,7 @@ class MultiShortestPath : public BinaryInputNode { class BFSShortestPath : public BinaryInputNode { public: static BFSShortestPath* make(QueryContext* qctx, PlanNode* left, PlanNode* right, size_t steps) { - return qctx->objPool()->add(new BFSShortestPath(qctx, left, right, steps)); + return qctx->objPool()->makeAndAdd(qctx, left, right, steps); } size_t steps() const { @@ -90,6 +91,7 @@ class BFSShortestPath : public BinaryInputNode { std::unique_ptr explain() const override; private: + friend ObjectPool; BFSShortestPath(QueryContext* qctx, PlanNode* left, PlanNode* right, size_t steps) : BinaryInputNode(qctx, Kind::kBFSShortest, left, right), steps_(steps) {} @@ -103,7 +105,7 @@ class ProduceAllPaths final : public BinaryInputNode { public: static ProduceAllPaths* make( QueryContext* qctx, PlanNode* left, PlanNode* right, size_t steps, bool noLoop) { - return qctx->objPool()->add(new ProduceAllPaths(qctx, left, right, steps, noLoop)); + return qctx->objPool()->makeAndAdd(qctx, left, right, steps, noLoop); } size_t steps() const { @@ -133,6 +135,7 @@ class ProduceAllPaths final : public BinaryInputNode { std::unique_ptr explain() const override; private: + friend ObjectPool; ProduceAllPaths(QueryContext* qctx, PlanNode* left, PlanNode* right, size_t steps, bool noLoop) : BinaryInputNode(qctx, Kind::kProduceAllPaths, left, right), steps_(steps), @@ -155,7 +158,7 @@ class ShortestPath final : public SingleInputNode { PlanNode* node, GraphSpaceID space, bool singleShortest) { - return qctx->objPool()->add(new ShortestPath(qctx, node, space, singleShortest)); + return qctx->objPool()->makeAndAdd(qctx, node, space, singleShortest); } PlanNode* clone() const override; @@ -211,6 +214,7 @@ class ShortestPath final : public SingleInputNode { } private: + friend ObjectPool; ShortestPath(QueryContext* qctx, PlanNode* node, GraphSpaceID space, bool singleShortest) : SingleInputNode(qctx, Kind::kShortestPath, node), space_(space), @@ -231,7 +235,7 @@ class ShortestPath final : public SingleInputNode { class CartesianProduct final : public SingleDependencyNode { public: static CartesianProduct* make(QueryContext* qctx, PlanNode* input) { - return qctx->objPool()->add(new CartesianProduct(qctx, input)); + return qctx->objPool()->makeAndAdd(qctx, input); } Status addVar(std::string varName); @@ -244,6 +248,7 @@ class CartesianProduct final : public SingleDependencyNode { std::unique_ptr explain() const override; private: + friend ObjectPool; CartesianProduct(QueryContext* qctx, PlanNode* input) : SingleDependencyNode(qctx, Kind::kCartesianProduct, input) {} @@ -257,7 +262,7 @@ class Subgraph final : public SingleInputNode { const std::string& resultVar, const std::string& currentStepVar, uint32_t steps) { - return qctx->objPool()->add(new Subgraph(qctx, input, resultVar, currentStepVar, steps)); + return qctx->objPool()->makeAndAdd(qctx, input, resultVar, currentStepVar, steps); } const std::string& resultVar() const { @@ -281,6 +286,7 @@ class Subgraph final : public SingleInputNode { } private: + friend ObjectPool; Subgraph(QueryContext* qctx, PlanNode* input, const std::string& resultVar, @@ -300,12 +306,13 @@ class Subgraph final : public SingleInputNode { class BiCartesianProduct final : public BinaryInputNode { public: static BiCartesianProduct* make(QueryContext* qctx, PlanNode* left, PlanNode* right) { - return qctx->objPool()->add(new BiCartesianProduct(qctx, left, right)); + return qctx->objPool()->makeAndAdd(qctx, left, right); } std::unique_ptr explain() const override; private: + friend ObjectPool; BiCartesianProduct(QueryContext* qctx, PlanNode* left, PlanNode* right); }; } // namespace graph diff --git a/src/graph/planner/plan/Logic.h b/src/graph/planner/plan/Logic.h index ee34599c3e2..a8cbd9f791a 100644 --- a/src/graph/planner/plan/Logic.h +++ b/src/graph/planner/plan/Logic.h @@ -15,12 +15,13 @@ namespace graph { class StartNode final : public PlanNode { public: static StartNode* make(QueryContext* qctx) { - return qctx->objPool()->add(new StartNode(qctx)); + return qctx->objPool()->makeAndAdd(qctx); } PlanNode* clone() const override; private: + friend ObjectPool; explicit StartNode(QueryContext* qctx) : PlanNode(qctx, Kind::kStart) {} void cloneMembers(const StartNode&); @@ -56,7 +57,7 @@ class Select final : public BinarySelect { PlanNode* ifBranch = nullptr, PlanNode* elseBranch = nullptr, Expression* condition = nullptr) { - return qctx->objPool()->add(new Select(qctx, input, ifBranch, elseBranch, condition)); + return qctx->objPool()->makeAndAdd