libaquery: optimizations that reduces vector copy.

dev
Bill 2 years ago
parent bea97a909a
commit 9caee2819f

@ -30,14 +30,14 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>false</EnableASAN>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>true</EnableASAN>
@ -45,7 +45,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>false</EnableASAN>
<EnableFuzzer>false</EnableFuzzer>
@ -53,7 +53,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v142</PlatformToolset>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<EnableASAN>true</EnableASAN>

@ -930,7 +930,7 @@ class udf(ast_node):
cname = get_legal_name(args)
self.var_table[args] = cname
self.args.append(cname)
front = [*self.code_list, ', '.join([f'auto {a}' for a in self.args])]
front = [*self.code_list, ', '.join([f'const auto& {a}' for a in self.args])]
self.code_list = []
self.with_storage = False

@ -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);

@ -93,4 +93,3 @@ Global
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {572EA821-8162-4161-9AC2-464C79F08B47}
EndGlobalSection
EndGlobal

@ -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)

@ -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

@ -22,4 +22,4 @@ FIELDS TERMINATED BY ","
SELECT pairCorr(c, b) * d, sum(a), b
FROM test1
group by c,b,d
order by b ASC
order by b ASC

@ -24,11 +24,11 @@ LOAD DATA INFILE "data/test.csv"
INTO TABLE tt
FIELDS TERMINATED BY ","
CREATE TABLE sale(Mont INT, sales INT)
CREATE TABLE sale1(Mont INT, sales INT)
LOAD DATA INFILE "data/moving_avg.csv"
INTO TABLE sale
INTO TABLE sale1
FIELDS TERMINATED BY ","
select sd(a) + sales from tt, sale where tt.a = sale.Mont
select sd(a) + sales from tt, sale1 where tt.a = sale1.Mont

@ -1,6 +1,6 @@
AGGREGATION FUNCTION covariances2(x, y, w){
AGGREGATION FUNCTION covariances2(x, y, win){
xmeans := 0.;
ymeans := 0.;
l := _builtin_len;
@ -11,6 +11,7 @@ AGGREGATION FUNCTION covariances2(x, y, w){
ymeans := y[0];
_builtin_ret[0] := 0.;
}
w := win;
if (w > l)
w := l;
for (i := 1, j:= 0; i < w; i := i+1) {

Loading…
Cancel
Save