* 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.
* ---------------------------------------------------------------------------------------
*
* vecsetop.h
*
*
* IDENTIFICATION
* src/include/vecexecutor/vecsetop.h
*
* ---------------------------------------------------------------------------------------
*/
#ifndef VECSETOP_H_
#define VECSETOP_H_
#include "vecexecutor/vechashtable.h"
#include "vecexecutor/vecnodes.h"
extern VecSetOpState* ExecInitVecSetOp(VecSetOp* node, EState* estate, int eflags);
extern VectorBatch* ExecVecSetOp(VecSetOpState* node);
extern void ExecEndVecSetOp(VecSetOpState* node);
extern void ExecReScanVecSetOp(VecSetOpState* node);
extern void ExecEarlyFreeVecHashedSetop(VecSetOpState* node);
#define SETOP_PREPARE 0
#define SETOP_BUILD 1
#define SETOP_FETCH 2
typedef struct VecSetOpStatePerGroupData {
long numLeft;
long numRight;
} VecSetOpStatePerGroupData;
struct SetOpHashCell {
SetOpHashCell* m_next;
VecSetOpStatePerGroupData perGroup;
hashVal m_val[FLEXIBLE_ARRAY_MEMBER];
};
struct SetOpStateLog {
bool restore;
int lastIdx;
int numOutput;
SetOpHashCell* lastCell;
};
class setOpTbl : public hashBasedOperator {
public:
setOpTbl(VecSetOpState* runtime);
~setOpTbl(){};
void ResetNecessary(VecSetOpState* node);
void Build();
VectorBatch* Probe();
VectorBatch* (setOpTbl::*Operation)();
private:
void BindingFp();
VectorBatch* RunHash();
template <bool simple>
VectorBatch* RunSort();
* Dump the cell to the m_scanBatch(not the parameter batch) for outputNum times,
* batch is the data source and need to be stored in m_lastBatch because it is not scaned over,
* idx indicate the index of next processed row.
*/
bool DumpOutput(SetOpHashCell* cell, VectorBatch* batch, int& outputNum, int idx);
hashSource* GetHashSource();
void (setOpTbl::*m_BuildFun)(VectorBatch* batch);
void (setOpTbl::*m_BuildScanBatch)(SetOpHashCell* cell);
template <bool simple>
void BuildSetOpTbl(VectorBatch* batch);
template <bool simple>
void InitCell(SetOpHashCell* cell, VectorBatch* batch, int row, int flag);
template <bool simple>
bool MatchKey(VectorBatch* batch, int batchIdx, SetOpHashCell* cell);
void BuildScanBatch(SetOpHashCell* cell);
template <bool expand>
int computeHashTableSize(int oldsize);
void HashTableGrowUp();
FORCE_INLINE uint32 get_bucket(uint32 hashvalue)
{
return hashvalue & (uint32)(m_size - 1);
}
template <bool simple>
void AllocHashSlot(VectorBatch* batch, int i, int flag, bool foundMatch, SetOpHashCell* cell);
ScalarValue getHashValue(SetOpHashCell* hashentry);
private:
VecSetOpState* m_runtime;
int m_outerColNum;
int m_runState;
int m_firstFlag;
AttrNumber m_junkCol;
hashSource* m_hashSource;
int m_cmd;
SetOpStateLog m_statusLog;
VectorBatch* m_scanBatch;
SetOpHashCell** m_setOpHashData;
int m_size;
VectorBatch* m_lastBatch;
int m_max_hashsize;
bool m_can_grow;
int64 m_grow_threshold;
};
#define DO_SETOPERATION(tbl) (((setOpTbl*)tbl)->*(((setOpTbl*)tbl)->Operation))()
#endif