libaquery: optimizations that reduces vector copy.

This commit is contained in:
2022-09-09 20:42:04 +08:00
parent bea97a909a
commit 9caee2819f
9 changed files with 52 additions and 39 deletions
+3 -19
View File
@@ -278,25 +278,9 @@ int test_main()
printf("sibal: %p %p\n", aa, bb);
const char* qs[]= {
"SELECT MIN(3)-MAX(2);",
"CREATE TABLE stocks(timestamp INT, price INT);",
"INSERT INTO stocks VALUES(1, 15);;",
"INSERT INTO stocks VALUES(2,19); ",
"INSERT INTO stocks VALUES(3,16);",
"INSERT INTO stocks VALUES(4,17);",
"INSERT INTO stocks VALUES(5,15);",
"INSERT INTO stocks VALUES(6,13);",
"INSERT INTO stocks VALUES(7,5);",
"INSERT INTO stocks VALUES(8,8);",
"INSERT INTO stocks VALUES(9,7);",
"INSERT INTO stocks VALUES(10,13);",
"INSERT INTO stocks VALUES(11,11);",
"INSERT INTO stocks VALUES(12,14);",
"INSERT INTO stocks VALUES(13,10);",
"INSERT INTO stocks VALUES(14,5);",
"INSERT INTO stocks VALUES(15,2);",
"INSERT INTO stocks VALUES(16,5);",
"SELECT price, timestamp FROM stocks WHERE (((price - timestamp) > 1) AND (NOT ((price * timestamp) < 100))) ;",
"CREATE TABLE test1(a INT, b INT, c INT, d INT);",
"COPY OFFSET 2 INTO test1 FROM 'W:/gg/AQuery++/data/test.csv' ON SERVER USING DELIMITERS ',';",
"SELECT sum(a), b, c, d FROM test1 GROUP BY c, b, d ORDER BY b ;",
};
n_recv = sizeof(qs)/(sizeof (char*));
n_recvd = const_cast<char**>(qs);
-1
View File
@@ -93,4 +93,3 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {572EA821-8162-4161-9AC2-464C79F08B47}
EndGlobalSection
EndGlobal
+19 -3
View File
@@ -32,6 +32,8 @@ public:
typedef ColRef<_Ty> Decayed_t;
const char* name;
types::Type_t ty = types::Type_t::ERROR;
ColRef(const ColRef<_Ty>& vt) : vector_type<_Ty>(vt) {}
ColRef(ColRef<_Ty>&& vt) : vector_type<_Ty>(std::move(vt)) {}
ColRef() : vector_type<_Ty>(0), name("") {}
ColRef(const uint32_t& size, const char* name = "") : vector_type<_Ty>(size), name(name) {}
ColRef(const char* name) : name(name) {}
@@ -62,10 +64,22 @@ public:
}
ColRef(const char* name, types::Type_t ty) : name(name), ty(ty) {}
using vector_type<_Ty>::operator[];
using vector_type<_Ty>::operator=;
//using vector_type<_Ty>::operator=;
using vector_type<_Ty>::subvec;
using vector_type<_Ty>::subvec_memcpy;
using vector_type<_Ty>::subvec_deep;
ColRef<_Ty>& operator= (const _Ty& vt){
vector_type<_Ty>::operator=(vt);
return *this;
}
ColRef<_Ty>& operator =(const ColRef<_Ty>& vt) {
vector_type<_Ty>::operator=(vt);
return *this;
}
ColRef<_Ty>& operator =(ColRef<_Ty>&& vt) {
vector_type<_Ty>::operator=(std::move(vt));
return *this;
}
ColView<_Ty> operator [](const vector_type<uint32_t>&idxs) const {
return ColView<_Ty>(*this, idxs);
}
@@ -100,6 +114,8 @@ public:
void* monetdb_get_col();
};
template<>
class ColRef<void> : public ColRef<int>{};
template<typename _Ty>
class ColView {
@@ -151,11 +167,11 @@ public:
ret[i] = orig[idxs[i]];
return ret;
}
ColView<_Ty> subvec(uint32_t start, uint32_t end) {
ColView<_Ty> subvec(uint32_t start, uint32_t end) const {
uint32_t len = end - start;
return ColView<_Ty>(orig, idxs.subvec(start, end));
}
ColRef<_Ty> subvec_deep(uint32_t start, uint32_t end) {
ColRef<_Ty> subvec_deep(uint32_t start, uint32_t end) const{
uint32_t len = end - start;
ColRef<_Ty> subvec(len);
for (uint32_t i = 0; i < len; ++i)
+19 -6
View File
@@ -29,9 +29,14 @@ public:
this->size = vt.size;
this->capacity = vt.capacity;
this->container = (_Ty*)malloc(size * sizeof(_Ty));
memcpy(container, vt.container, sizeof(_Ty) * size);
if (capacity) {
puts("copy");
this->container = (_Ty*)malloc(size * sizeof(_Ty));
memcpy(container, vt.container, sizeof(_Ty) * size);
}
else {
this->container = vt.container;
}
}
void inline _move(vector_type<_Ty>&& vt) {
if (capacity > 0) free(container);
@@ -39,7 +44,7 @@ public:
this->size = vt.size;
this->capacity = vt.capacity;
this->container = vt.container;
puts("move");
vt.size = vt.capacity = 0;
vt.container = 0;
}
@@ -60,7 +65,7 @@ public:
}
constexpr vector_type() noexcept : size(0), capacity(0), container(0) {};
constexpr vector_type(_Ty* container, uint32_t len) noexcept : size(len), capacity(0), container(container) {};
constexpr vector_type(const vector_type<_Ty>& vt) noexcept : capacity(0) {
constexpr explicit vector_type(const vector_type<_Ty>& vt) noexcept : capacity(0) {
_copy(vt);
}
constexpr vector_type(vector_type<_Ty>&& vt) noexcept : capacity(0) {
@@ -107,18 +112,26 @@ public:
return *this;
}
void emplace_back(_Ty _val) {
inline void grow() {
if (size >= capacity) { // geometric growth
uint32_t new_capacity = size + 1 + (size >> 1);
_Ty* n_container = (_Ty*)malloc(new_capacity * sizeof(_Ty));
memcpy(n_container, container, sizeof(_Ty) * size);
memset(n_container + size, 0, sizeof(_Ty) * (new_capacity - size));
if (capacity)
free(container);
container = n_container;
capacity = new_capacity;
}
}
void emplace_back(const _Ty& _val) {
grow();
container[size++] = _val;
}
void emplace_back(_Ty&& _val) {
grow();
container[size++] = std::move(_val);
}
iterator_t erase(iterator_t _it) {
#ifdef DEBUG
// Do bound checks