* Copyright (c) 2020 Huawei Technologies Co.,Ltd.
*
* openGauss is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* ---------------------------------------------------------------------------------------
*
* vsonichashagg.h
* sonic hash agg class and class member declare
*
* IDENTIFICATION
* src/include/vectorsonic/vsonichashagg.h
*
* ---------------------------------------------------------------------------------------
*/
#ifndef VSONICHASHAGG
#define VSONICHASHAGG
#include "nodes/plannodes.h"
#include "vecexecutor/vecagg.h"
#include "vectorsonic/vsonichash.h"
#include "vectorsonic/vsonicpartition.h"
class SonicHashAgg : public SonicHash {
public:
SonicHashAgg(VecAggState* node, int arrSize);
~SonicHashAgg(){};
VectorBatch* Run();
void Build();
VectorBatch* Probe();
SonicHashSource* GetHashSource();
bool ResetNecessary(VecAggState* node);
int getFileNum()
{
if (m_partFileSource != NULL)
return m_partNum * m_buildOp.cols;
else
return 0;
}
private:
* Fowllowing functions are called for preparing all information needed in sonic hashagg node.
*/
void initAggInfo();
void initMemoryControl();
void initBatch();
void initDataArray();
void initHashTable();
void initMatchFunc(TupleDesc desc, uint16* keyIdx, uint16 keyNum);
void BindingFp();
* Build hash table and process match procedure.
*/
template <bool simpleType>
bool matchValue(ScalarVector* pVector, uint16 keyIdx, int16 pVectorIdx, uint32 cmpIdx);
template <bool simpleType>
void matchArray(ScalarVector* pVector, uint16 keyIdx, uint16 cmpRows);
template <bool useSegHashTable, bool unique_check>
void buildAggTblBatch(VectorBatch* batch);
int64 insertHashTbl(VectorBatch* batch, int idx, uint32 hashval, uint32 hashLoc);
void calcHashContextSize(MemoryContext ctx, int64* memorySize, int64* freeSize);
void judgeMemoryOverflow(char* opname, int planId, int dop, Instrumentation* instrument, int64 size_needed);
bool judgeMemoryAllowExpand();
template <bool expand, bool logit>
int64 calcHashTableSize(int64 oldSize);
void AllocHashTbl(VectorBatch* batch, int idx, uint32 hashval, int hashLoc);
void tryExpandHashTable();
void expandHashTable();
int64 calcLeftRows(int64 rows_in_mem);
uint16 calcPartitionNum(long numGroups);
void resetVariableMemberIfNecessary(int partNum);
void initPartition(SonicHashPartition** partSource);
SonicHashPartition** createPartition(uint16 num_partitions);
void releaseAllFileHandlerBuffer();
* Following functions are used for calculating agg function result and build the final result.
*/
void AggregationOnScalar(VecAggInfo* aggInfo, ScalarVector* pVector, int idx);
void BatchAggregation(VectorBatch* batch);
void Profile(char* stats, bool* can_wlm_warning_statistics);
void BuildScanBatchSimple(int idx);
void BuildScanBatchFinal(int idx);
VectorBatch* ProducerBatch();
void (SonicHashAgg::*m_buildScanBatch)(int idx);
typedef void (SonicHashAgg::*pKeyMatchArrayFunc)(ScalarVector* pVector, uint16 keyIdx, uint16 cmpRows);
typedef bool (SonicHashAgg::*pKeyMatchValueFunc)(
ScalarVector* pVector, uint16 keyIdx, int16 pVectorIdx, uint32 cmpIdx);
private:
VecAggState* m_runtime;
int m_runState;
int m_strategy;
int64 m_tupleCount;
int64 m_colWidth;
int m_arrayElementSize;
int64 m_arrayExpandSize;
int m_fill_table_rows;
ExprContext* m_econtext;
SonicHashSource* m_sonicHashSource;
SonicHashPartition** m_partFileSource;
SonicHashPartition** m_overflowFileSource;
uint16 m_partNum;
uint16 m_overflowNum;
int m_currPartIdx;
* Create a list of the tuple columns that actually need to be stored in
* hashtable entries. The incoming tuples from the outer plan node will
* contain grouping columns, other columns referenced in targetlist and
* qual, columns used to compute the aggregate functions, and perhaps just
* junk columns we don't use at all. Only columns of the first two types
* need to be stored in the hashtable, and getting rid of the others can
* make the table entries significantly smaller.
*/
* number of columns needed in hash table
*/
uint16 m_hashNeed;
uint16* m_hashInBatchIdx;
uint16* m_keyIdxInSonic;
uint16 m_aggNum;
uint16 m_finalAggNum;
bool* m_aggCount;
uint16* m_aggIdx;
bool m_keySimple;
finalAggInfo* m_finalAggInfo;
FmgrInfo* m_equalFuncs;
VectorBatch* m_scanBatch;
VectorBatch* m_proBatch;
VectorBatch* m_outBatch;
VectorBatch* m_sourceBatch;
bool m_useSegHashTbl;
int m_segNum;
SonicDatumArray* m_segBucket;
SonicDatumArray* m_next;
bool m_enableExpansion;
void (SonicHashAgg::*m_buildFun)(VectorBatch* batch);
double m_hashbuild_time;
double m_calcagg_time;
pKeyMatchArrayFunc* m_arrayKeyMatch;
pKeyMatchValueFunc* m_valueKeyMatch;
uint16 m_missIdx[BatchMaxSize];
uint16 m_missNum;
uint16 m_suspectIdx[BatchMaxSize];
uint16 m_suspectNum;
uint32 m_bucketLoc[BatchMaxSize];
uint32 m_orgLoc[BatchMaxSize];
};
#endif